Bug #50757 [Opn->Bgs]: PDO MYSQL issue with BIT data type not setting correct value
Edit report at http://bugs.php.net/bug.php?id=50757&edit=1
ID: 50757
Updated by: uw@php.net
Reported by: christian at activemediaworks dot com
Summary: PDO MYSQL issue with BIT data type not setting correct
value
-Status: Open
+Status: Bogus
Type: Bug
Package: PDO related
Operating System: MAC OSX 10.5.8
PHP Version: 5.2.12
New Comment:
No bug here. This is how crappy PDO works ever since. If you don't
specify a bind type, binding will use strings. Your code:
$stmt = $db->prepare("INSERT INTO mytable (mybit) VALUES (?)");
$stmt->execute(array(0));
... is equivalent to:
$stmt = $db->prepare("INSERT INTO mytable (mybit) VALUES ('0')");
$stmt->execute(array(0));
Which in turn inserts 1 into the BIT column.
Previous Comments:
------------------------------------------------------------------------
[2010-01-14 20:22:48] christian at activemediaworks dot com
Description:
------------
When trying to insert a row with a 0-value into a column of type BIT(1),
if the value for the column is not hard-coded into SQL statement, it
causes the value to be inserted to become 1. If it is hardcoded, it is
okay.
Reproduce code:
---------------
/* This results in the value of the column being set to 1 (incorrect)
*/
$db = new PDO ( "mysql:dbname=db1234;host=localhost", "user1234",
"pass1234" );
$stmt = $db->prepare("INSERT INTO mytable (mybit) VALUES (?)");
$stmt->execute(array(0));
db_disconnect($db);
/* This results in the value of the column being set to 0 (correct) */
$db = new PDO ( "mysql:dbname=db1234;host=localhost", "user1234",
"pass1234" );
$stmt = $db->prepare("INSERT INTO mytable (mybit) VALUES (0)");
$stmt->execute();
db_disconnect($db);
Actual result:
--------------
The first example inserts a row with the column value set to 1 (wrong)
The second example inserts a row with the column value set to 0 (right)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=50757&edit=1
Thread (3 messages)