|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-04-01 21:00 UTC] kenaniah at gmail dot com
Description: ------------ When using postgres via PDO and attempting to execute an INSERT or UPDATE query using $stmt->execute(array_values($data)) syntax, postgres returns an error for any boolean fields that may be present. Reproduce code: --------------- <?php // $db is my PDO connection object $values = array(true, false); $sql = "UPDATE table SET boolean_column1 = ?, boolean_column2 = ?"; $stmt = $db->prepare($sql); $stmt->execute($values); ?> Expected result: ---------------- PDO will recognize that the values in the array are boolean, and will provide these values to the prepared statement as correctly-formatted booleans. Actual result: -------------- PostgreSQL 8.1.9 returns an error stating that the provided values for the booleans are not in the correct format, and may need to be type-casted. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 03:00:01 2025 UTC |
I'm using php 5.6.4 on Windows and this bug is still present test case: <?php //CREATE TABLE booltest(name varchar(30) not null, bool_col BOOLEAN NOT NULL) $db = new PDO('pgsql:host=127.0.0.1 dbname=dev', 'postgres', '12Qwerty'); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $stmt = $db->prepare('INSERT INTO booltest (name, bool_col) VALUES (:name, :bool_col)'); $params = array( 'normal boolean true' => true, 'normal boolean false' => false, // this one will fail 'string boolean true' => 'true', 'string boolean false' => 'false', 'int boolean true' => 1, 'int boolean false' => 0 ); foreach ($params as $key => $value){ echo "$key..."; $stmt->execute(array('name' => $key, 'bool_col' => $value)); echo "OK! <br>"; } echo "all OK!";