Bug #57157 [Opn->Nab]: PDOStatement::execute() fails handling boolean 'false' parameter
| From: | cmb@php.net | Date: | Mon, 08 Feb 2021 14:33:27 +0000 |
| Subject: | Bug #57157 [Opn->Nab]: PDOStatement::execute() fails handling boolean 'false' parameter | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-232015@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=57157&edit=1
ID: 57157
Updated by: cmb@php.net
Reported by: neta at blackbit dot it
Summary: PDOStatement::execute() fails handling boolean
'false' parameter
-Status: Open
+Status: Not a bug
Type: Bug
Package: PDO PgSQL
Operating System: OSX/NetBSD/FreeBSD
PHP Version: 5.1.4
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
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>
Previous Comments:
------------------------------------------------------------------------
[2014-03-31 21:48:55] 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
------------------------------------------------------------------------
[2014-02-06 22:09:55] 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;
?>
------------------------------------------------------------------------
[2006-07-26 07:37:30] 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.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=57157&edit=1