#49255 [NEW]: PDO fails to insert boolean FALSE to MySQL in prepared statement
| From: | carysmith at creighton dot edu | Date: | Fri, 14 Aug 2009 15:53:18 +0000 |
| Subject: | #49255 [NEW]: PDO fails to insert boolean FALSE to MySQL in prepared statement | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-141056@lists.php.net to get a copy of this message | ||
From: carysmith at creighton dot edu
Operating system: Windows 2003 Ent.
PHP version: 5.2.10
PHP Bug Type: PDO related
Bug description: PDO fails to insert boolean FALSE to MySQL in prepared statement
Description:
------------
Before I report the bug, would just like to say that PDO is excellent and
I am enjoying working with it.
The Issue:
When attempting to insert a Boolean FALSE into a MySQL Boolean column, the
insert fails. Inserting a 0 does not.
The following example code is borrowed from another post which was similar
http://bugs.php.net/bug.php?id=38386 and modified
to accommodate how I am
using it.
Reproduce code:
---------------
<?php
$dbh = new PDO( 'mysql:host=localhost; dbname=Testing', 'DevUser',
'P@ssw0rd!');
// Create table
$query = 'CREATE TABLE Testing.test_boolean(TheBoolean BOOLEAN);';
$createStatement = $dbh->prepare( $query);
$createStatement->execute();
// Attempt to insert Boolean records into table - (FALSE insert fails
without error)
$query = 'insert into Testing.test_boolean set TheBoolean = ?;';
$statement = $dbh->prepare( $query);
$statement->execute(array(true));
$statement->execute(array(false));
// However by replacing Boolean with integers does work
$statement->execute(array(1));
$statement->execute(array(0));
?>
Expected result:
----------------
4 rows added to the table:
1
0
1
0
Actual result:
--------------
3 rows added to the table:
1
1
0
Investigation of the MySQL logs shows the Boolean FALSE is inserted as an
empty string '' which fails. Please verify if I am missing something or
this cannot be reproduced. In the meantime I am changing the code to use
numbers instead of Boolean.
--
Edit bug report at http://bugs.php.net/?id=49255&edit=1
--
Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=49255&r=trysnapshot52
Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=49255&r=trysnapshot53
Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=49255&r=trysnapshot60
Fixed in SVN: http://bugs.php.net/fix.php?id=49255&r=fixed
Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=49255&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=49255&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=49255&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=49255&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=49255&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=49255&r=support
Expected behavior: http://bugs.php.net/fix.php?id=49255&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=49255&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=49255&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=49255&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=49255&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=49255&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=49255&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=49255&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=49255&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=49255&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=49255&r=mysqlcfg