php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #60191 wrong result
Submitted: 2011-11-01 13:25 UTC Modified: 2011-11-01 14:56 UTC
From: j dot veder at advanceu dot nl Assigned: danbrown (profile)
Status: No Feedback Package: *General Issues
PHP Version: Irrelevant OS: windows
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 — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
34 - 9 = ?
Subscribe to this entry?

 
 [2011-11-01 13:25 UTC] j dot veder at advanceu dot nl
Description:
------------
---
From manual page: http://www.php.net/function.mysql-query#refsect1-function.mysql-query-examples
---
<?php
$result = mysql_query('SELECT * WHERE 1=1');
if (!$result) {//this does not return false ever!!!!!!!!! returns on fail: 'result resource(7)' after mysql_fetch_assoc() returns bool(false)
    die('Invalid query: ' . mysql_error());
}

?>


Test script:
---------------
<?php
$result = mysql_query('SELECT * WHERE 1=1');
print_r($result);
if (!$result) {
    die('Invalid query: ' . mysql_error());
}

?>

Expected result:
----------------
false

Actual result:
--------------
result resource(7)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-11-01 13:36 UTC] anon at anon dot anon
Tried it, and I get "false", and "Invalid query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE 1=1' at line 1".
 [2011-11-01 14:50 UTC] danbrown@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: danbrown
 [2011-11-01 14:56 UTC] danbrown@php.net
You indicate that you were using mysql_fetch_assoc(), yet your code does not 
show it anywhere.  Also, if your test script is exactly as shown, you haven't 
even created a database link.  That said:

<?php
$result = @mysql_query('SELECT * WHERE 1=1');
die(PHP_EOL.var_dump($result).PHP_EOL);
?>

$ php kjh.php 
bool(false)

What do you see when you run the code exactly as shown above?
 [2011-11-01 14:56 UTC] danbrown@php.net
-Status: Feedback +Status: No Feedback
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 28 11:01:32 2024 UTC