php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50757 PDO MYSQL issue with BIT data type not setting correct value
Submitted: 2010-01-14 20:22 UTC Modified: 2010-03-24 12:55 UTC
From: christian at activemediaworks dot com Assigned:
Status: Not a bug Package: PDO related
PHP Version: 5.2.12 OS: MAC OSX 10.5.8
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
19 + 41 = ?
Subscribe to this entry?

 
 [2010-01-14 20:22 UTC] 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)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-03-24 12:55 UTC] uw@php.net
-Status: Open +Status: Bogus
 [2010-03-24 12:55 UTC] uw@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.
 [2011-12-09 23:48 UTC] dipan9876 at hotmail dot com
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 10:01:28 2024 UTC