php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54978 mysql_query() returns true with a SELECT statement
Submitted: 2011-06-02 17:38 UTC Modified: 2013-02-18 00:34 UTC
Votes:9
Avg. Score:4.8 ± 0.6
Reproduced:8 of 8 (100.0%)
Same Version:2 (25.0%)
Same OS:7 (87.5%)
From: radu dot dineiu at gmail dot com Assigned: mysql (profile)
Status: No Feedback Package: MySQL related
PHP Version: 5.3.6 OS: Any
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: radu dot dineiu at gmail dot com
New email:
PHP Version: OS:

 

 [2011-06-02 17:38 UTC] radu dot dineiu at gmail dot com
Description:
------------
This doesn't happen often, but it does happen sometimes when the database server 
interrupts the connection during a query. Seems to be related to the fact that 
libmysqlclient's mysql_query() may return success, even if an error occurred, as 
described at:

http://dev.mysql.com/doc/refman/5.5/en/null-mysql-store-result.html

Test script:
---------------
$resource = mysql_query('SELECT test FROM test');
if ($resource === true) {
    throw new Exception('mysql_query() returned true for SELECT');
}

Expected result:
----------------
An exception should not be thrown, because the documentation for mysql_query() at 
php.net clearly states that a SELECT query will only ever return false or a 
resource.

Actual result:
--------------
An exception is thrown, because mysql_query() returns true with a SELECT query.

Patches

mysql_query_true_patch.txt (last revision 2011-06-02 15:39 UTC by radu dot dineiu at gmail dot com)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-07-20 10:55 UTC] uw@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: mysql
 [2011-07-20 10:55 UTC] uw@php.net
Are you using libmysql, if so, which version? Can you reproduce with mysqlnd? 

And, yes, looks like we need the patch. I wonder if its libmysql version dependent.

Thanks!
 [2011-07-24 03:57 UTC] radu dot dineiu at gmail dot com
Yes, this happens with PHP's mysql_* functions using libmysqlclient, not mysqlnd. 
I don't know if it happens with mysqlnd as well, I couldn't test that, and now I 
can't get the same environment again.
 [2013-02-18 00:34 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 14:01:29 2024 UTC