|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62593 Emulate prepares behave strangely with PARAM_BOOL
Submitted: 2012-07-18 10:04 UTC Modified: 2012-10-30 14:45 UTC
Avg. Score:4.8 ± 0.4
Reproduced:10 of 10 (100.0%)
Same Version:4 (40.0%)
Same OS:4 (40.0%)
From: mascione at sviluppo dot toscana dot it Assigned: willfitch
Status: Closed Package: PDO related
PHP Version: 5.3.14 OS: Ubuntu 10.04
Private report: No CVE-ID:
 [2012-07-18 10:04 UTC] mascione at sviluppo dot toscana dot it
On postgresql when I use ATTR_EMULATE_PREPARES binding params or values with PARAM_BOOL behave strangely.

Disabling ATTR_EMULATE_PREPARES resolve the problem.

(driver specific PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT generates same problem)

(Related to bug #38386 ?)

Test script:
$db = new PDO('pgsql:dbname=testdb;user=postgres');
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
//CREATE TABLE t(a boolean, b boolean)
$stmt = $db->prepare("INSERT INTO t(a,b) VALUES (true,false)");
$stmt = $db->prepare("INSERT INTO t(a,b) VALUES (:test,:test)");
$stmt->bindValue('test', false, PDO::PARAM_BOOL);
$stmt = $db->prepare("SELECT * FROM t WHERE :test");
$stmt->bindValue('test', true, PDO::PARAM_BOOL);

Expected result:
Works without errors.

Actual result:
    [0] => 00000
    [1] => 
    [2] => 
    [0] => 42804
    [1] => 7
    [2] => ERROR:  column "a" is of type boolean but expression is of type integer
LINE 1: INSERT INTO t(a,b) VALUES (0,'0')
HINT:  You will need to rewrite or cast the expression.
    [0] => 42804
    [1] => 7
    [2] => ERROR:  argument of WHERE must be type boolean, not type integer


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-07-19 06:15 UTC] ploginoff at gmail dot com
Yes! _Yesterday_ I have * with the same bug. Solution: install 5.3.13 or disable emulate prepares (but it is sometimes necessary).
 [2012-09-17 16:13 UTC]
-Status: Open +Status: Assigned -Assigned To: +Assigned To: willfitch
 [2012-09-17 16:17 UTC]
I have confirmed this.  The issue with disabling emulation prepares for this 
purpose is that it sends the query through PQprepare, then PQexec.  If you're 
using middleware such as pgbouncer, this won't work.
 [2012-09-17 19:19 UTC]
-Status: Assigned +Status: Verified
 [2012-09-18 10:04 UTC] v dot picture at free dot fr
Same problem with the stock version on Ubuntu 12.04: PHP 5.3.10-1ubuntu3.4 
(built: Sep 12 2012)
I hope this problem will be solved soon.
 [2012-09-20 16:36 UTC]
Pull request for this fix:
 [2012-10-10 21:30 UTC]
This was accepted and is awaiting merge.
 [2012-10-17 07:50 UTC] franck dot borel at ub dot uni-freiburg dot de
I am running the test script on SLES11 SP2 with PHP 5.2.14 and I have the same error described here!
 [2012-10-30 14:45 UTC]
-Status: Verified +Status: Closed
 [2012-10-30 14:45 UTC]
The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at

 For Windows:
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2015 The PHP Group
All rights reserved.
Last updated: Tue Dec 01 02:01:31 2015 UTC