From: dan at manifestwebdesign dot com Operating system: linux PHP version: 5.2.9 PHP Bug Type: MySQL related Bug description: Mysql selects/deletes rows it shouldn't when using IS NULL
Description: ------------ Mysql ignores the IS NULL in the WHERE statement when the query is executed from php. In the example I give, the AddressID is auto_increment primary key. As you can see from the output, the address ID gets a value of 65 for the inserted row. I then DELETE WHERE AddressID IS NULL and the row is removed. It will also return the row when I execute SELECT * FROM Address WHERE AddressID IS NULL. It happens in with mysql_query, PDO::exec() or PDO::query() and with or without ` around the table name. Reproduce code: --------------- //PHP 5.2.9 on Hostmonster.com mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); mysql_select_db(DB_NAME); mysql_query("INSERT INTO `Address` (StreetAddress) VALUES ('blah')"); $result = mysql_query("SELECT * FROM `Address`"); while($row = mysql_fetch_assoc($result)){ print_r($row); } mysql_query("DELETE FROM `Address` WHERE `AddressID` IS NULL"); $result = mysql_query("SELECT * FROM `Address`"); while($row = mysql_fetch_assoc($result)){ print_r($row); } Expected result: ---------------- Array ( [AddressID] => 65 [NameOrCompany] => [StreetAddress] => blah [City] => [State] => [Zip] => [Country] => [DateTimeCreated] => [DateTimeModified] => ) Array ( [AddressID] => 65 [NameOrCompany] => [StreetAddress] => blah [City] => [State] => [Zip] => [Country] => [DateTimeCreated] => [DateTimeModified] => ) Actual result: -------------- Array ( [AddressID] => 65 [NameOrCompany] => [StreetAddress] => blah [City] => [State] => [Zip] => [Country] => [DateTimeCreated] => [DateTimeModified] => ) -- Edit bug report at http://bugs.php.net/?id=48251&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=48251&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=48251&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=48251&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=48251&r=fixedcvs Fixed in CVS and need be documented: http://bugs.php.net/fix.php?id=48251&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=48251&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=48251&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=48251&r=needscript Try newer version: http://bugs.php.net/fix.php?id=48251&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=48251&r=support Expected behavior: http://bugs.php.net/fix.php?id=48251&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=48251&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=48251&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=48251&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=48251&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=48251&r=dst IIS Stability: http://bugs.php.net/fix.php?id=48251&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=48251&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=48251&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=48251&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=48251&r=mysqlcfg