I am currently using mysqli to crate a connection to my database. My host server doesnt support PDO connections so that is why I am using mysqli. When making the connection I am getting this error:
Fatal error: Call to undefined method mysqli_result::fetchAll()
Is fetchAll() not part of mysqli?
PHP Connect to DB
$mysqli = new mysqli('localhost', 'user', 'password', 'database');
if (mysqli_connect_error()) {
die('Connect Error (' . mysqli_connect_errno() . ') '
. mysqli_connect_error());
}
else {
echo ('Success... ');
}
$sql = "SELECT *
FROM `categories`
WHERE `master` = 0";
$statement = $mysqli->query($sql);
$list = $statement->fetchAll();
When you call
$mysqli->query($sql), this can return amysqli_resultobject, or the valuefalsein case of an error. I think that your query is not successful, and returns the value false, and of course if you ask forfalse->fetchAll()this will give an error message.So you have to check first, if the query was successful (use the
===operator and check forfalse), and afterwards you can work with the result of the query.P.S. That’s why i never write functions myself, with mixed typed return values…