|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-08-08 20:10 UTC] bryan at bdrew dot co dot uk
Description: ------------ 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->execute(); $statement->bindValue( 1, false, PDO::PARAM_BOOL); $statement->execute(); 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. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 15:00:01 2025 UTC |
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: <?php $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;" ); $db->exec( "CREATE TABLE TestPDO (ColT BOOLEAN, ColF BOOLEAN) ENGINE = InnoDB" ); $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"); ?>