mysqli fetch_all() not a valid function?

Phil picture Phil · Jul 14, 2011 · Viewed 96k times · Source

Thanks to the answers I have figured out that I am unable to use fetch_all() because i am using PHP 5.2.17 - fetch_assoc with while loop worked.


The function I am using fetch_all is coming back with this error:

Fatal error: Call to undefined method mysqli_result::fetch_all() in

$mysqli = new mysqli($host, $username, $password, $database);
$query = "LONG QUERY that works, tested in phpmyadmin"
$result = $mysqli->query($query);
$result->fetch_all(); or  $mysqli->fetch_all() tried both
mysqli_fetch_all() was already tried.
$mysqli->close(); 

I am able to connect to the DB and I have pulled single rows. When I place the query in PHPMYADMIN I get 5 rows back.

Does this function even work? Is there a way I can place my data into an assoc array on my own?

Answer

Karolis picture Karolis · Jul 14, 2011

This function is available since PHP 5.3.0. Possibly your version is older. Use fetch_assoc() instead.

while ($row = $result->fetch_assoc()) {
    // do what you need.
}