I have a script that is supposed to read from the database and return an array which is used by another function to display a table. However the function is throwing an error.
Fatal error: Call to a member function fetch_array() on a non-object in C:\xampp\htdocs\nu\userClass.php on line 205
I don’t know what could be the error because I have already created an object for the MySQLi class. Here is my code
function getUser($user_id)
{
require("config.php");
//TODO Clean variables
$dbc = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
/* check connection */
if (mysqli_connect_errno())
{
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$query2 = "SELECT family.Position, food.Meal "."FROM family, food "."WHERE family.Position = food.Position";
$result = $dbc->query($query2);
$row = $result->fetch_array();
/* close connection */
$dbc->close();
return $row;
}
This error message seems to say that you have an error in your SQL query.
Try replacing the call to $dbc->query() by the following lines :
This will show you a more detailed error message.