The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →This warning means mysql_num_rows() received false instead of a query-result resource. The row-count call is where the problem becomes visible; for a SELECT, the earlier mysql_query() call returns false when it fails. Diagnose that query and its connection before trying to count rows.
What the warning means
The legacy mysql_num_rows() function expects a result resource. If it receives a boolean, it cannot count rows. In this situation the boolean is usually false, returned because the preceding query failed. PHP’s documentation for mysql_query() describes the return behavior; the mysql_num_rows() manual documents the row-count function.
As an Amazon Associate I earn from qualifying purchases.
That is different from a successful query that returns zero rows: a valid result set with no matches is still a result, and can be counted. Do not treat a failed query as an empty result.
Recommended Free Tools
Trace the failure before line 54
- Check the connection and selected database. Confirm that connection setup succeeded and that the intended database was selected before issuing the query. The SitePoint example does not check those steps, so it cannot establish whether either failed in a particular installation. Stop the operation or report an application-safe error if setup fails.
- Keep the SQL and result in separate variables. For example, use
$sqlfor the statement text and$resultfor the return value ofmysql_query($sql). Reusing a variable named$queryfor both makes it harder to tell whether it contains SQL or the query outcome. - Inspect the exact SQL sent to the database. Log or display it only in a controlled development environment, then verify the table and column names, syntax, and values. Check the database error at the query line rather than waiting until
mysql_num_rows()reports the bad value. - Check how the search terms are assembled. In the code discussed in the SitePoint Forums thread, community participant John_Betong points out that
$i = 0is placed inside aforeachloop. That resets$ion every iteration, so it becomes 1 each time and can prevent the intended SQL-building branch from changing. Move initialization before the loop and inspect the resultingORterms. Also verify that$qhas the expected value. The thread does not include the database’s actual error, so this is a likely flaw in that snippet, not a proven explanation for every instance of the warning. - Handle failure before counting or fetching. In legacy code, test the query result for failure and stop downstream row-count or fetch operations if it failed. Record detailed database diagnostics in a controlled log or development environment; do not expose raw database errors to site visitors.
Why replacing the row-count call is not the fix
Changing the line number, suppressing the warning, or swapping out mysql_num_rows() does not repair a failed query. The cause could be connection setup, database selection, malformed SQL, missing or misspelled tables or columns, or invalid input construction. The available SitePoint example leaves the source of $q and the exact database error unknown, so identify the cause from the actual query and error in your own application.
#1 Best Overall
Use a supported database API in current PHP
The original PHP mysql_* extension was deprecated in PHP 5.5.0 and removed in PHP 7.0.0. PHP directs developers to MySQLi or PDO_MySQL instead; see the mysql_query() documentation for its compatibility note. Do not try to restore the removed extension as a fix for a current PHP installation.
MySQLi and PDO_MySQL are both supported alternatives. Select the one that fits the application’s existing database layer and the team’s chosen API style; the cited documentation does not establish a universal winner. Keep connection, query, and result handling within the same API.
MySQLi
With mysqli::query(), a successful result-producing query returns a mysqli_result; failure returns false unless error reporting is configured to raise an exception. Check or catch the failure according to the application’s configuration before using the result. If a query contains variable input, PHP recommends parameterized prepared statements; see mysqli::prepare().
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallPDO_MySQL
With PDO, query failure behavior depends on the configured error mode: a call may return false or throw an exception. Check PDO::query() and handle errors consistently with that setting. For variable values, prepare the statement and execute it with bound values rather than concatenating input into SQL.
Quick Recap
Rank #4
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.




