|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-09-10 21:37 UTC] wez@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 15:00:02 2025 UTC |
Description: ------------ When binding a boolean to a column in a prepared statement, PDO_PGSQL throws an exception. <?php $stmt = $DB->prepare( "insert into footable ( barbool ) values ( :bar )" ); $bool = false; $stmt->bindParam( ":bar", $bool ); $stmt->execute(); ?> Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for type boolean: ""' in /home/root/test.php:13 Stack trace: #0 /home/root/test.php(13): PDOStatement->execute() #1 {main} thrown in /home/root/test.php on line 13 It tried to run: 2005-07-24 21:00:00 LOG: statement: insert into footable ( barbool ) values ( '' ) When $bool = true, it runs: 2005-07-24 21:02:10 LOG: statement: insert into footable ( barbool ) values ( '1' ) which is also invalid. '1' and '' are invalid types for PGSQL booleans. If I use $stmt->bindParam( ":bar", $bool, PDO_PARAM_INT ); to convert to 0 and 1, PGSQL also errors as 1 and 0 are not valid for booleans. If it had quotes around it, it would be Ok. Postgres has several ways to accept booleans: http://www.postgresql.org/docs/8.0/interactive/datatype-boolean.html (for ver 8.0, although has been such since 6.0 or so, if not long before) * Ideal solution would be a PDO_PARAM_BOOL that would convert to applicable type based on database driver. Expected result: ---------------- Statements get executed correctly.