Home  >  Article  >  Backend Development  >  Why am I getting \"Call to undefined method mysqli_result::fetch_all()\"?

Why am I getting \"Call to undefined method mysqli_result::fetch_all()\"?

DDD
DDDOriginal
2024-11-03 14:53:02966browse

Why am I getting

mysqli fetch_all() Function Error: Undefined Method

The error message "Fatal error: Call to undefined method mysqli_result::fetch_all() in" indicates that the fetch_all() method is not supported in the version of PHP being used.

Compatibility Issue

The fetch_all() function was introduced in PHP 5.3.0, so versions prior to that will not have access to it. In this case, the user is using PHP 5.2.17, which predates the introduction of fetch_all().

Alternative Method

As a workaround, the user can use the fetch_assoc() method with a while loop to retrieve rows from the query result. The syntax is as follows:

<code class="php">while ($row = $result->fetch_assoc()) {
    // Do something with the row data.
}</code>

Example

The following code snippet demonstrates how to use fetch_assoc() with a while loop:

<code class="php">$mysqli = new mysqli($host, $username, $password, $database);
$query = "LONG QUERY that works, tested in PHPMyAdmin";
$result = $mysqli->query($query);
while ($row = $result->fetch_assoc()) {
    print_r($row);
}
$mysqli->close();</code>

The above is the detailed content of Why am I getting \"Call to undefined method mysqli_result::fetch_all()\"?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn