From: Operating system: Linux PHP version: 5.2.14 Package: PDO related Bug Type: Bug Bug description:PDO converts (int)0 to NULL
Description: ------------ PDO Driver for MySQL, client library version 5.0.84 When using the bindColumn method of the pdo statement object, PDO converts the value Null to the number 0, if you set the type to PDO::PARAM_INT. Nevertheless PDO did'n convert a Null Value, when you select PDO::PARAM_STR as type. So PDO::PARAM_STR can handle Null-Values, but PDO::PARAM_INT can't. Test script: --------------- <?php $DB_HOST = 'localhost'; $DB_NAME = '***'; $DB_PASSWORD = '***; $DB_USERNAME = '***; $Dsn = 'mysql:host='.$DB_HOST.';dbname='.$DB_NAME; $Database = new PDO($Dsn, $DB_USERNAME, $DB_PASSWORD); $Database->setAttribute(PDO::ATTR_ERRMODE , PDO::ERRMODE_EXCEPTION); $Database->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_BOUND); $Sql = <<<SQL SELECT '', Null, 0, Null SQL; $Statement = $Database->prepare($Sql); $Statement->bindColumn(1, $Test1, PDO::PARAM_STR); // string(0) "" $Statement->bindColumn(2, $Test2, PDO::PARAM_STR); // NULL $Statement->bindColumn(3, $Test3, PDO::PARAM_INT); // int(0) $Statement->bindColumn(4, $Test4, PDO::PARAM_INT); // NULL $Statement->execute(); $Statement->fetch(); var_dump($Test1); var_dump($Test2); var_dump($Test3); var_dump($Test4); ?> Expected result: ---------------- string(0) "" NULL int(0) NULL Actual result: -------------- string(0) "" NULL int(0) int(0) -- Edit bug report at http://bugs.php.net/bug.php?id=53132&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=53132&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=53132&r=trysnapshot53 Try a snapshot (trunk): http://bugs.php.net/fix.php?id=53132&r=trysnapshottrunk Fixed in SVN: http://bugs.php.net/fix.php?id=53132&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=53132&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=53132&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=53132&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=53132&r=needscript Try newer version: http://bugs.php.net/fix.php?id=53132&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=53132&r=support Expected behavior: http://bugs.php.net/fix.php?id=53132&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=53132&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=53132&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=53132&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=53132&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=53132&r=dst IIS Stability: http://bugs.php.net/fix.php?id=53132&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=53132&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=53132&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=53132&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=53132&r=mysqlcfg