Edit report at https://bugs.php.net/bug.php?id=50757&edit=1

 ID:                 50757
 Comment by:         dipan9876 at hotmail dot com
 Reported by:        christian at activemediaworks dot com
 Summary:            PDO MYSQL issue with BIT data type not setting
                     correct value
 Status:             Bogus
 Type:               Bug
 Package:            PDO related
 Operating System:   MAC OSX 10.5.8
 PHP Version:        5.2.12
 Block user comment: N
 Private report:     N

 New Comment:

PDO is seriously crap. Having used .NET's beautiful ADO.Net, PDO almost feels 
like 
something thrown together by a college student. It's no wonder the community is 
dropping PHP like a brick if this is the sort of developments being made these 
days.


Previous Comments:
------------------------------------------------------------------------
[2010-03-24 12:55:33] u...@php.net

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.

------------------------------------------------------------------------
[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 https://bugs.php.net/bug.php?id=50757&edit=1

Reply via email to