mysqli_stmt::get_result() is undefined on a prepared statement
Fatal error: Uncaught Error: Call to undefined method mysqli_stmt::get_result()Short answer
get_result() exists only when PHP's mysqli is built on the MySQL Native Driver (mysqlnd). If your PHP was built on the older libmysqlclient, the method is missing. Check which library you run. On PHP 8.2 and newer mysqlnd is the only option; on an older build, upgrade PHP or read rows with bind_result() instead.
Fix it fast
1Find out which cause you have
List the loaded PHP extensions for the PHP that runs your site. If mysqlnd is not in the list, mysqli is using a different client library and get_result() is not available.
php -v php -m | grep -i -E "mysqli|mysqlnd"2Match what you see, then jump to its fix
- 1
mysqli is listed but mysqlnd is not; PHP is older than 8.2mysqli was compiled against libmysqlclient, not mysqlndFix - 2
php -v shows 5.3 or lowerPHP is 5.3 or older, from before mysqlnd was the defaultFix - 3
Shared hosting or a locked PHP build where mysqlnd is not availableYou cannot change the server, so fetch rows another wayFix
- 1
What does the error look like?
Fatal error: Uncaught Error: Call to undefined method mysqli_stmt::get_result()Call to undefined method mysqli_stmt::get_result()
Cause 1 of 3
mysqli was compiled against libmysqlclient, not mysqlnd
1Check
The manual's build matrix says mysqlnd is the default from PHP 5.4 and the only option from PHP 8.2. A build from PHP 5.4 to 8.1 made with --with-mysqli=/path/to/mysql_config uses libmysqlclient instead, and get_result() is documented as available only with mysqlnd.
php -m | grep -i -E 'mysqli|mysqlnd'2Fix
Move to PHP 8.2 or newer, where mysqlnd is the only client library. If you compile PHP yourself, configure it with plain --with-mysqli and leave out the /path/to/mysql_config form.
./configure --with-mysqli [other options]3Verify
Run the script again, or ask PHP whether the method now exists.
php -r 'var_dump(method_exists("mysqli_stmt", "get_result"));'Confirmed by php.net
Cause 2 of 3
PHP is 5.3 or older, from before mysqlnd was the default
1Check
In the manual's matrix, PHP 5.3 defaults to libmysqlclient and PHP 5.0 to 5.2 cannot use mysqlnd at all.
php -v2Fix
Upgrade PHP. Old releases no longer get security fixes, so a version bump fixes this error and the missing patches together.
# install a supported PHP release and its MySQL extension (mysqli)
# with your distribution's package manager, then restart PHP3Verify
Confirm the new version and the extension.
php -v
php -m | grep -i mysqliConfirmed by php.net
Cause 3 of 3
You cannot change the server, so fetch rows another way
1Check
The manual lists bind_result() with fetch() as the way to read a prepared statement without get_result(). It needs one variable per selected column, bound after execute().
grep -rn 'get_result' --include=*.php .2Fix
Replace get_result() and fetch_assoc() with bind_result() and a fetch() loop. Call store_result() before fetching if you want a buffered result set.
$stmt = $mysqli->prepare("SELECT id, label FROM test WHERE id = ?");
$stmt->bind_param("i", $id);
$stmt->execute();
$stmt->bind_result($outId, $outLabel);
while ($stmt->fetch()) {
echo $outId, " ", $outLabel, "\n";
}3Verify
Run the page and check that rows print without the fatal error.
php your-script.phpConfirmed by php.net
How do I stop it coming back?
- Run PHP 8.2 or newer in every environment, so local, staging and production use the same client library.
- Use the same PHP version for the command line and the web server, and check php -m on both.
- Keep mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT) at the top of database code so failures throw instead of returning false.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Back end
Android gets HTML instead of JSON from a PHP API
org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject
The response body is not JSON.
2 causes, each with a fixBack end
Apache returns 403 when a URL contains %3F
a request like /page%3Fname=test is refused while /page?name=test works
Recent Apache httpd blocks a rewrite when the request contains an encoded question mark (%3F) and the rewritten target has a literal ?.
2 causes, each with a fixBack end
Apache returns 500 with Premature end of script headers
500 Internal Server Error
Apache ran your script, but the script printed no valid HTTP header before its output.
3 causes, each with a fixBack end
Apache returns 503 or 504 because PHP-FPM did not answer in time
Error dispatching request
Apache sent the request to PHP-FPM and gave up waiting.
3 causes, each with a fixBack end
AWS SDK for PHP cannot get credentials from the instance profile metadata server
Error retrieving credentials from the instance profile metadata server.
The SDK tries the EC2 instance metadata service when it has no valid credentials from anywhere earlier in its chain.
4 causes, each with a fixBack end
AWS SDK for PHP rejects requests: the signature is from the future
Signature not yet current: {date} is still later than {date}
AWS compares the timestamp in your signed request with its own clock.
2 causes, each with a fix