Bug #50757 [Opn->Bgs]: PDO MYSQL issue with BIT data type not setting correct value

From: Date: Wed, 24 Mar 2010 11:55:33 +0000
Subject: Bug #50757 [Opn->Bgs]: PDO MYSQL issue with BIT data type not setting correct value
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-148925@lists.php.net to get a copy of this message
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)

« previous php.bugs (#148925) next »