php - Member function non object -


i have made simple mysqli function wrapper use connect with. when try use it, fatal error

"fatal error: call member function query() on non-object in /home/cgateams/public_html/home.cga/test.php on line 5"  line 5: $res = $dblink->query("select * test"); 

test.php

include('includes/db/config.php');  $dblink = db_connect(); $res = $dblink->query("select * test"); while ($res = $row) {     echo $row['test']; } 

config.php

//database server $host = 'localhost'; $dbname = 'dbname';  //sanitized data $dbuser = 'dbuser'; $dbpass = 'dbpass';  // db connect 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 cga database currently');    else    return $dbonnect;  } 

you're missing $. should be:

if (!$dbconnect) 

and further down in return value, you've got typo:

return $dbconnect; 

the error you're getting because mysqli object not being returned (because of typos).

also, @ using prepared statements mysqli - they're powerful , more secure inline queries, when passing params.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -