php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #57157 PDOStatement::execute() fails handling boolean 'false' parameter
Submitted: 2006-07-26 07:37 UTC Modified: 2021-02-08 14:33 UTC
Votes:16
Avg. Score:4.8 ± 0.6
Reproduced:15 of 15 (100.0%)
Same Version:2 (13.3%)
Same OS:4 (26.7%)
From: neta at blackbit dot it Assigned: cmb (profile)
Status: Not a bug Package: PDO PgSQL
PHP Version: 5.1.4 OS: OSX/NetBSD/FreeBSD
Private report: No CVE-ID: None
 [2006-07-26 07:37 UTC] neta at blackbit dot it
Description:
------------
PDOStatement::execute() fails handling boolean 'false' 
parameter

To be noticed that the PHP TRUE bool value is handled 
correctly instead.


Reproduce code:
---------------
Long story short to reproduce:
- prepare $stat using '?' placeholders;
- assign the PHP FALSE bool value to one of these, when $stat->execute( $params_array );

Verified against PHP-5.1.4 PDO (PostgreSQL 8.1.4), both from pristine builds.

Expected result:
----------------
A (php) FALSE parameter is expected to be translated into a 
valid SQL "FALSE". 

According to my DBMS this is the case for "f", 0, FALSE.
I don't know if this bug is DB-specific though.

Actual result:
--------------
Instead of "FALSE" or 0 or "f" or whatever, it sends out to 
DBMS an empty string "". 

My DBMS (postgresql) complains profusely about this.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-02-06 22:09 UTC] karsten at typo3 dot org
This is a test case that reprocess the error for me, using

PHP 5.5.8 (compiled using MacPorts)
PostgreSQL 9.3.2
SQLite library 3.8.2
OS X 10.9.1

<?php

/*
CREATE TABLE "booleantest" (
  "persistence_object_identifier" serial NOT NULL,
  "hidden" boolean NOT NULL
);
 */

$handle = new PDO('pgsql:host=127.0.0.1 dbname=testdb', 'foo', 'bar');
$handle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$statement = $handle->prepare('INSERT INTO booleantest (hidden) VALUES (?)');

// works as expected
$statement->execute(array(TRUE));
echo 'TRUE has been inserted' . PHP_EOL;

// dies with
// PDOException: SQLSTATE[22P02]: Invalid text representation: 7 ERROR:  invalid input syntax for type boolean: ""
$statement->execute(array(FALSE));
echo 'FALSE has been inserted' . PHP_EOL;

?>
 [2014-03-31 21:48 UTC] davividal at gmail dot com
I can reproduce this problem. Versions I'm running:

PHP 5.5.3-1ubuntu2.2 (cli) (built: Feb 28 2014 20:06:05) 
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies
    with Zend OPcache v7.0.3-dev, Copyright (c) 1999-2013, by Zend Technologies


Distributor ID:	Ubuntu
Description:	Ubuntu 13.10
Release:	13.10
Codename:	saucy

PostgreSQL 9.3.3 on x86_64-unknown-linux-gnu, compiled by gcc-4.4.real (Debian 
4.4.5-8) 4.4.5, 64-bit
 [2017-03-01 22:34 UTC] adambaratz@php.net
-Package: PDO +Package: PDO PgSQL
 [2021-02-08 14:33 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2021-02-08 14:33 UTC] cmb@php.net
From the documentation of PDOStatement::execute()[1]:

| An array of values with as many elements as there are bound
| parameters in the SQL statement being executed. All values are
| treated as PDO::PARAM_STR.

Coercing TRUE to string yields "1"; coercing FALSE to string
yields "". Thus, the reported behavior is expected.  Explicitly
bind as PDO::PARAM_INT instead.

[1] <https://www.php.net/manual/en/pdostatement.execute.php>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 09:01:29 2024 UTC