|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38386 PDO fails to pass Boolean paramatersl
Submitted: 2006-08-08 20:10 UTC Modified: 2006-08-17 01:00 UTC
Avg. Score:4.2 ± 0.7
Reproduced:11 of 11 (100.0%)
Same Version:1 (9.1%)
Same OS:4 (36.4%)
From: bryan at bdrew dot co dot uk Assigned:
Status: No Feedback Package: PDO related
PHP Version: 5.1.4 OS: Linux (Fedora5)
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: bryan at bdrew dot co dot uk
New email:
PHP Version: OS:


 [2006-08-08 20:10 UTC] bryan at bdrew dot co dot uk
Using PDO to write boolean variables to a database table via bindValue() does not work.
The attached code fails to insert either of the two rows.
No errors are generated, the code just doesn't work.  Its as if NULL is being passed through to the query.
Substituting the booleans values for the integers 1 and 0 does work.
Database MySQL 5.1 using the InnoDB engine.

Reproduce code:
$query = 'insert into TestDb set MyBoolean=?';

$statement = $DbConnection->prepare( $query);
$statement->bindValue( 1, true, PDO::PARAM_BOOL);
$statement->bindValue( 1, false, PDO::PARAM_BOOL);

Expected result:
Two rows added to the table TestDb.

Row 1 with MyBoolean set to TRUE
Row 2 with MyBoolean set to FALSE

Actual result:
Nothing is inserted into the database and no errors are reported.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-08-08 21:05 UTC]
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.

 [2006-08-09 09:17 UTC] bryan at bdrew dot co dot uk
Follows is example code highlighting the bug.
Code requires MySQl database 'TestDb' created, together with a user 'tester' and password 'password' with create and insert rights to the database.

Expected result is a table TestDb.TestTbl with the following contents:

Actual result is a table TestDb.TestTbl with the following contents:

$dbh = new PDO( 'mysql:host=localhost; dbname=TestDb', 'tester', 'password');

// Create table
$query = 'create table TestDb.TestTbl (MyBoolean boolean)';
$createStatement = $dbh->prepare( $query);

// Attempt to insert boolean records into table - this does not work
$query = 'insert into TestDb.TestTbl set MyBoolean=?';
$statement = $dbh->prepare( $query);
$statement->bindValue( 1, true, PDO::PARAM_BOOL);
$statement->bindValue( 1, false, PDO::PARAM_BOOL);

// However by replacing booleans with integers does work
$statement->bindValue( 1, 0, PDO::PARAM_BOOL);
$statement->bindValue( 1, 1, PDO::PARAM_BOOL);

 [2006-08-09 13:41 UTC]
Please try using this CVS snapshot:
For Windows:

I've tried this on latest CVS and MySQL 5.0.22 and it works 
exactly as intended. Boolean of 1/0 (true/false) are being 
 [2006-08-17 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2015-12-15 18:55 UTC] cruxic at gmail dot com
This bug still exists in PHP 7.0 with MySQL.  It really ought to be fixed.  For me it only bites when PDO::ATTR_EMULATE_PREPARES is false.  Here's a complete test case:

$db = new PDO(  "mysql:host=localhost;dbname=DBNAME", "DBUSER", "DBPASS",
				array(  PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
						PDO::ATTR_EMULATE_PREPARES   => false) );
$db->exec( "DROP TABLE IF EXISTS TestPDO;" );

$stmt = $db->prepare( "INSERT INTO TestPDO (ColT, ColF) VALUES (:ColT, :ColF)" );
$stmt->bindValue( ":ColT", TRUE,  PDO::PARAM_BOOL );
$stmt->bindValue( ":ColF", FALSE, PDO::PARAM_BOOL );
if (!$stmt->execute())
	echo("Bug!  Execute returned false! errorCode() was: " . $stmt->errorCode() . "\n");
$rowCount = $db->query("SELECT COUNT(*) FROM TestPDO")->fetch(PDO::FETCH_NUM)[0];
echo("rowCount $rowCount (expected 1)\n");
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Thu May 19 00:04:05 2022 UTC