I have the connection file...
CODE
/* DATABASE ROUTINES */
function dbConnect() {
$dbhost = 'localhost';
$dbuser = '****_****'; $dbpass = '****'; $dbname = '****_****';
// mysqli - start
$mysqli = new mysqli("$dbhost", "$dbuser", "$dbpass", "$dbname");
// mysqli - end
}
/* END OF DATABASE ROUTINES */
and the query function that I use...
CODE
//Function to query the database.
function db_query($query) {
//$result = mysql_query($query) or db_error($query, mysql_errno(), mysql_error());
$result = $mysqli->query("$query");
return $result;
}
But get the following error...
Fatal error: Call to a member function query() on a non-object ..... on line 1216
which is this line...
CODE
$result = $mysqli->query("$query");
What is likely to be wrong with my code or method to access the data ?
The query itself has not changed.
I have just checked and I have not got a function of my own called 'query' either, so it is not that.
EDIT: I have just added extra code taken from php.net to show if the connection wored or not, no error only the host info shown. So I take it that the connection works. It has to be something with the actual db_query function. But looking at other pages I googled, they all show the same sort of query method, I even tried with and without the quotes around the string $result = $mysqli->query("$query"); and just $result = $mysqli->query("$query");
Just to see what would happen I tried to get my db_query to run the same query instead of what was in the $query string, and I get the same errors.
CODE
//Function to query the database.
function db_query($query) {
//$result = mysql_query($query) or db_error($query, mysql_errno(), mysql_error());
$result = $mysqli->query("SELECT * FROM `cats` WHERE 1");
return $result;
}
I am really at a loss as to why this won't work. Never used mysqli before.