Rik Nijdeken Rik Nijdeken - 1 year ago 263
PHP Question

Fatal error: Call to a member function fetch_all() on boolean

I am trying to make al the records in my database to a JSON format so i can use it in an app from me, but then i got this error

<b>Fatal error</b>: Call to a member function fetch_all() on boolean
i have tried changing
fetch_all to fetchall
but it did not help. this is my code that i use:

//Converting db values into json data


$conn = new mysqli('localhost','root','') or die(mysql_error());
$sql= 'SELECT * FROM wtd';

$data = $rs->fetch_all(MYSQLI_ASSOC);
echo json_encode($data);


I hope anyone can help me i am on a time limit.

Answer Source

This is because you have not selected any database. You can set the database like this:

$conn = new mysql('localhost', 'root', '', '<NAME_OF_DATABASE>');

Since you have not selected the database $conn->query() will return FALSE.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download