Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk3 min

PHP Fatal Error: Call to a Member Function fetch_assoc() on Boolean

The fetch_assoc() fatal error usually follows a failed MySQLi query. Check the query result and inspect the database error before fetching rows.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

This error means your MySQLi query failed and returned false, but your code then called fetch_assoc() as if it had returned a result set. The fix is to find and correct the database error reported by the query, then check for failure before fetching rows.

What the error means

fetch_assoc() is a method of a mysqli_result object. A successful SELECT, SHOW, DESCRIBE, or EXPLAIN query returns that kind of object; a failed query returns the boolean value false. Calling a result method on false causes the fatal error.

The fatal error is therefore a follow-on failure, not the original database problem. Also, it does not mean the query found no rows: a successful query with zero matching rows still returns a result object. The failure occurred while running the query or establishing the database operation.

Find the database error that happened first

Common causes include malformed SQL, a misspelled or missing table or column, invalid connection credentials, insufficient database permissions, an unavailable or closed connection, or a server limit. The specific cause depends on the SQL and the database environment, so inspect the error from the failed MySQLi operation rather than guessing from the later fetch_assoc() message.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Store the query result in a variable instead of chaining query() directly into fetch_assoc().
  2. Check whether the result is exactly false.
  3. If it failed, read $mysqli->error or use mysqli_error($mysqli) to get the last MySQLi error message.
  4. Use that message to correct the SQL, connection, schema, permission, or server issue.
  5. Fetch rows only after the query succeeds.
$result = $mysqli->query($sql);

if ($result === false) {
    throw new RuntimeException($mysqli->error);
}

while ($row = $result->fetch_assoc()) {
    // Process $row.
}

Using === false makes the failure check explicit. Once execution reaches the loop, a successful query with no matching rows simply runs zero iterations.

Choose how your application should handle query failures

Approach How the original failure appears Zero-row queries Best fit
Check for false and inspect $mysqli->error Your code detects failure at the query call and decides how to handle it. Handled separately: a successful result can still contain no rows. Applications that want to handle each query failure explicitly.
Enable strict MySQLi reporting With MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT, a failed operation raises a mysqli_sql_exception at the failing operation. A zero-row result is not a query exception. Applications that use exception handling for database failures.

Use explicit failure checks

The example above lets the calling code handle the error at the point where it runs the query. If you throw an exception, catch it only at a boundary where the application can recover or return a controlled response. Do not catch and silently ignore it; that hides the original problem and can lead to later failures that are harder to diagnose.

Use strict reporting for exceptions

MySQLi reporting can be configured so failed operations throw instead of allowing execution to continue with a false result:

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

$mysqli = new mysqli($host, $user, $password, $database);
$result = $mysqli->query($sql); // Throws if the operation fails.

Handle the resulting mysqli_sql_exception at an appropriate application boundary. This brings attention to the database operation that failed instead of letting the error surface later when the code tries to fetch a row.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Keep query diagnostics out of public error pages

During development, the database error message helps identify the failure. In production, do not display credentials, raw connection strings, or sensitive query parameters to visitors. Send diagnostic details to a protected log and show users a generic error page.

If SQL includes variable input, use a parameterized prepared statement, especially for values supplied by users. Properly formatted and escaped input is another option, but prepared statements separate values from the SQL statement.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Account for version and environment differences

The exact MySQLi error varies with the query, connection, server, and configuration. PHP and MySQLi reporting defaults can also differ by version and setup, so do not diagnose the issue from a numeric error code alone. When asking for help, record the PHP and MySQL or MariaDB versions, the SQL statement shape, the connection target, and the exact error text. PHP 8.4 also changes behavior for some server wait-timeout error codes, which is another reason not to hard-code a single code as the diagnosis.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.