php.net |  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
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:
Package:
Bug Type:
Summary:
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
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.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-09-10 21:37 UTC] wez@php.net
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 http://bugs.php.net/?id=33876 for more details.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Mon Oct 19 16:01:24 2020 UTC