Skip to content

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

@phaedrus428

Description

@phaedrus428

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions