0

接続に使用する単純な 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");

test.php

include('includes/db/config.php');

$dblink = db_connect();
$res = $dblink->query("select * from test");
while ($res = $row) {
    echo $row['test'];
}

config.php

//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; 
}
4

3 に答える 3