php-src icon indicating copy to clipboard operation
php-src copied to clipboard

mysqli_query returns fatal error when table in query doesn't exist

Open phaedrus428 opened this issue 4 years ago • 1 comments

Description

The mysqli_query function (https://www.php.net/manual/en/mysqli.query.php) is no longer returning false when the table does not exist. In PHP 8.0.16, false is returned, but in PHP 8.1.0 and PHP 8.1.3, a fatal error is received instead. The documentation does not say to expect this change.

Sample code:

<?php
$link = mysqli_connect($database_host, $database_username,
$database_password, $database_name, $database_port, $database_socket);
if ($link && mysqli_select_db($link, $database_name) {
$query = "SELECT userID FROM `users`";
$result = mysqli_query($link, $query);
} else {
echo "Connection Error";
exit();
}
?>

That results in a fatal error if the table doesn't exist, but mysqli_query should simply return false in that case.

PHP Version

PHP 8.1.0 and 8.1.3

Operating System

No response

phaedrus428 avatar Feb 24 '22 03:02 phaedrus428

Default for report_mode has been changed in PHP 8.1 https://www.php.net/manual/en/mysqli-driver.report-mode.php https://www.php.net/manual/en/migration81.incompatible.php#migration81.incompatible.mysqli

KapitanOczywisty avatar Feb 24 '22 04:02 KapitanOczywisty