如何在PHP中调用函数

我一直在学习如何创建会话对象的一些课程,这很好,如果我把完整的代码放到PHP文件上,一切都很棒!

我想做的是将它放在另一个模块(PHP文件)中,只需使用一行(或等效的)来执行此操作,例如GetSessiondata();

<?PHP
$sqlCon = new DBConnect("Databaselocation","Database","Usr","Pss");                     
$UserDataSet = $sqlCon->GetUserList("SELECT * FROM Users");

echo "<br /><br />";
echo "<br /><br />";

if ($UserDataSet)          
{               
    echo "<table>" . "<thead>" ;
    echo "<tr><th scope=\"col\">" . 'Usr' . "</th>";
    echo "<th scope=\"col\">" . 'Lvl' . "</th></tr></thead><tbody>";                
    foreach($UserDataSet as $data)
    {                                  
        echo "<td>" .$data->GetUsrName()."</td>" ;
        echo "<td>" .$data->GetUsrLevel()."</td></tr>" ;                                       
    }
    echo "<tfoot><tr><th scope=\"row\" colspan=\"2\">" . 'Total Users = 2' . "</th></tr></tfoot>";
    echo "</tbody>" . "</table>" ;  
}
else
    echo "nothing Found in DB!";
?>

解决方法:

您需要“需要”您要使用它的文件.

这是一个例子

Working with classes:

Whatever.PHP

class Whatever {
  public function __construct() {
    // Ever when the code is instantiated, this will be called too!
  }
  public function myMethod() {
    echo 'hello';
  }
}

的index.PHP

require_once('./Whatever.PHP');
$whatever = new Whatever();
$whatever->myMethod();

Without classes:

的functions.PHP

function whatever(){ echo 'hello'; }

index.PHP文件

require_once('./functions.PHP');
whatever();

阅读更多:

要求:http://php.net/manual/es/function.require.php

Require_once:http://php.net/manual/es/function.require-once.php

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...