我制作了一个简单的 mysqli 函数包装器,用于连接。当我尝试使用它时,我得到一个致命错误
"Fatal error: Call to a member function query() on a non-object in /home/cgateams/public_html/home.cga/test.php on line 5"
Line 5: $res = $dblink->query("select * from test");
测试.php
include('includes/db/config.php');
$dblink = db_connect();
$res = $dblink->query("select * from test");
while ($res = $row) {
echo $row['test'];
}
配置文件
//Database server
$host = 'localhost';
$dbname = 'dbname'; //sanitized data
$dbuser = 'dbuser';
$dbpass = 'dbpass';
// db connect to nm database
function db_connect()
{
global $host, $dbuser, $dbpass, $dbname;
$dbconnect = new mysqli($host, $dbuser, $dbpass, $dbname);
if (!dbconnect)
throw new Exception('Could not connect to CGA database currently');
else
return $dbonnect;
}