|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53647 mysql_num_rows falsely returns NULL on error
Submitted: 2011-01-04 12:18 UTC Modified: 2011-01-04 13:02 UTC
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: justus at abi007 dot info Assigned:
Status: Not a bug Package: MySQL related
PHP Version: Irrelevant OS: Ubuntu 10 Server
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: justus at abi007 dot info
New email:
PHP Version: OS:


 [2011-01-04 12:18 UTC] justus at abi007 dot info
mysql_num_rows returns NULL for invalid input data, like Strings/Booleans/Null/etc. 
In regards to the documentation this should be bool(false)
"Return Values
The number of rows in a result set on success or FALSE on failure."

Because it is likely better that invalid input data leads to a different failure handling I propose that you add "or NULL for invalid input data" to the documentation of Return Values to fix this.

Test script:

Expected result:

Actual result:
Warning: mysql_num_rows() expects parameter 1 to be resource, string given in - on line 2


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-01-04 13:02 UTC]
-Status: Open +Status: Bogus -Type: Documentation Problem +Type: Bug
 [2011-01-04 13:02 UTC]
Failed parameter checks within PHP functions result in NULL being
returned. This is expected (and standard) behaviour across the PHP
standard library.

 [2011-01-04 13:17 UTC] justus at abi007 dot info
That this is the expected behaviour is the point, because the documentation implies it isn't.

Please correct me if I'm wrong, but this "standard behaviour" is undocumented behaviour and thus useless. If this means writing the proposed update into every "Result Values" field, then so be it, right now it's not even close to ideal.

PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Fri Mar 24 20:03:41 2023 UTC