|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #56464 PDO_PGSQL throws exception binding a boolean
Submitted: 2005-07-24 21:09 UTC Modified: 2005-09-10 21:37 UTC
From: pecl dot php dot net at sharpdreams dot com Assigned: wez (profile)
Status: Closed Package: PDO_PGSQL (PECL)
PHP Version: 5_1 CVS-2005-07-24 (dev) OS: Any
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: pecl dot php dot net at sharpdreams dot com
New email:
PHP Version: OS:


 [2005-07-24 21:09 UTC] pecl dot php dot net at sharpdreams dot com
When binding a boolean to a column in a prepared statement, PDO_PGSQL throws an exception.


$stmt = $DB->prepare( "insert into footable ( barbool ) values ( :bar )" );

$bool = false;

$stmt->bindParam( ":bar", $bool );



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:

(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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-09-10 21:37 UTC]
PDO_PARAM_BOOL was somehow missing from the list of exported constants.  The issue have been resolved on the tip of the 5.1 branch.

See for more details.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Jun 13 20:01:31 2024 UTC