From: red at ixney dot net Operating system: Win XP Pro PHP version: 4.3.2 PHP Bug Type: MySQL related Bug description: (or) and (||) not the same
Description: ------------ I always thought '||' and 'or' was the same. Combined with a mysql_query() however, they are not. These lines are the same: mysql_query("$var") or die("help!"); mysql_query("$var") || die("help!"); where $var is a DROP, INSERT or CREATE query, but they are *not* the same if $var is a SELECT query; the returned value will not be a 'Resource ID' in the latter line. Reproduce code: --------------- mysql_query("DROP TABLE IF EXISTS foobar") || die('Cannot drop table'); mysql_query("CREATE TABLE IF NOT EXISTS foobar (foo INT NOT NULL AUTO_INCREMENT, bar TINYINT(1), PRIMARY KEY (foo))") || die('Cannot make table'); // Let's insert some random stuff mysql_query("INSERT INTO foobar (bar) VALUES (0)") || die('Cannot add values 1'); mysql_query("INSERT INTO foobar (bar) VALUES (1)") || die('Cannot add values 2'); mysql_query("INSERT INTO foobar (bar) VALUES (0)") or die('Cannot add values 3'); mysql_query("INSERT INTO foobar (bar) VALUES (1)") or die('Cannot add values 4'); $handle1 = mysql_query("SELECT * FROM foobar WHERE 1") || die('Cannot select'); $handle2 = mysql_query("SELECT * FROM foobar WHERE 1") or die('Cannot select'); echo '$handle1 is '.$handle1.'<br><br>'; echo '$handle2 is '.$handle2.'<br><br>'; Expected result: ---------------- $handle1 is Resource id #2 $handle2 is Resource id #3 Actual result: -------------- $handle1 is 1 $handle2 is Resource id #3 -- Edit bug report at http://bugs.php.net/?id=26734&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=26734&r=trysnapshot4 Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=26734&r=trysnapshot5 Fixed in CVS: http://bugs.php.net/fix.php?id=26734&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=26734&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=26734&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=26734&r=needscript Try newer version: http://bugs.php.net/fix.php?id=26734&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=26734&r=support Expected behavior: http://bugs.php.net/fix.php?id=26734&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=26734&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=26734&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=26734&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=26734&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=26734&r=dst IIS Stability: http://bugs.php.net/fix.php?id=26734&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=26734&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=26734&r=float