Bug #69856 [NEW]: bindColumn() casts null zero if PDO::PARAM_INT is used
| From: | abcaeffchen at gmail dot com | Date: | Wed, 17 Jun 2015 03:07:14 +0000 |
| Subject: | Bug #69856 [NEW]: bindColumn() casts null zero if PDO::PARAM_INT is used | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-193585@lists.php.net to get a copy of this message | ||
From: abcaeffchen at gmail dot com
Operating system: Windows
PHP version: 5.6.10
Package: PDO MySQL
Bug Type: Bug
Bug description:bindColumn() casts null zero if PDO::PARAM_INT is used
Description:
------------
PDO fetches fields to strings by default. If the field contains NULL in
database the returned value will also be null.
But if using PDOStatement::bindColumn with PDO::PARAM_INT, all null
values are casted to zero (as integer), so from the PHP side one cannot
tell if the database field contains zero or null.
The same happens with PDO::PARAM_BOOL. Here null is casted to false.
There is a workaround to this: After turning off emulated prepared
statements the returned values have the expected types. But this results
in bug #69257.
Test script:
---------------
$db = new
PDO('mysql:host=127.0.0.1;dbname=my_db;charset=UTF8',$user,$pass);
// Let field contain NULL in all (matching) rows
$stmt = $db->prepare('SELECT field FROM table WHERE other_field = ?');
$stmt->execute([1]);
$stmt->bindColumn(1,$field,PDO::PARAM_INT);
$stmt->fetch(PDO::FETCH_BOUND);
var_dump($field); // 0 (integer)
--
Edit bug report at https://bugs.php.net/bug.php?id=69856&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=69856&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=69856&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=69856&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=69856&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=69856&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=69856&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=69856&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=69856&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=69856&r=support
Expected behavior: https://bugs.php.net/fix.php?id=69856&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=69856&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=69856&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=69856&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=69856&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=69856&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=69856&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=69856&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=69856&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=69856&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=69856&r=mysqlcfg