Edit report at http://bugs.php.net/bug.php?id=53132&edit=1
ID: 53132 Updated by: [email protected] Reported by: novitools dot novi at web dot de Summary: PDO converts (int)0 to NULL -Status: Assigned +Status: Feedback Type: Bug Package: PDO related Operating System: Linux PHP Version: 5.2.14 Assigned To: mysql Block user comment: N New Comment: 5.2 only gets critical security updates. "This release marks the end of the active support for PHP 5.2. Following this release the PHP 5.2 series will receive no further active bug maintenance. Security fixes for PHP 5.2 might be published on a case by cases basis. All users of PHP 5.2 are encouraged to upgrade to PHP 5.3.", http://www.php.net/archive/2010.php#id2010-07-22-1 Please try with 5.3 Previous Comments: ------------------------------------------------------------------------ [2010-10-21 19:44:51] novitools dot novi at web dot de 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 this bug report at http://bugs.php.net/bug.php?id=53132&edit=1
