php.net |  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
Votes:1
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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
30 - 6 = ?
Subscribe to this entry?

 
 [2011-01-04 12:18 UTC] justus at abi007 dot info
Description:
------------
mysql_num_rows returns NULL for invalid input data, like Strings/Booleans/Null/etc. 
In regards to the documentation this should be bool(false)

http://php.net/mysql_num_rows
"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:
---------------
<? 
var_dump(mysql_num_rows('test'));
?>

Expected result:
----------------
bool(false)

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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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

Closing.
 [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.

Regards,
Justus
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 13:01:30 2024 UTC