Bug #71059 [Opn->Dup]: Undetected error in PDO when INSERTing with PARAM_BOOL
| From: | nikic@php.net | Date: | Fri, 11 Dec 2020 15:06:28 +0000 |
| Subject: | Bug #71059 [Opn->Dup]: Undetected error in PDO when INSERTing with PARAM_BOOL | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-231023@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=71059&edit=1
ID: 71059
Updated by: nikic@php.net
Reported by: tobias dot marstaller at enlifor dot com
Summary: Undetected error in PDO when INSERTing with
PARAM_BOOL
-Status: Open
+Status: Duplicate
Type: Bug
Package: PDO MySQL
Operating System: Windows 8.1 Enterprise
PHP Version: 5.6.16
Block user comment: N
Private report: N
New Comment:
Same issue as bug #66632, which has been fixed for a while already.
Previous Comments:
------------------------------------------------------------------------
[2015-12-08 12:12:48] tobias dot marstaller at enlifor dot com
Clarified bug title
------------------------------------------------------------------------
[2015-12-08 12:09:05] tobias dot marstaller at enlifor dot com
Description:
------------
Szenario Setup:
- A MySQL table with a column TINYINT(4) NOT NULL DEFAULT 0 (lets call it col in the context of this
bug report)
- A PDO connection to the MySQL Server with that table that has been set up with these attributes:
$pdo->setAttribute(PDO::ATTR_EMULATE_PERPARES, 0);
If you now try to insert a row into that table and pass that column a value of 0 as PDO::PARAM_BOOL,
the row is not inserted. PDOStatement::execute() returns false. However, PDOStatement::errorInfo()
does not indicate an error and no exception is thrown, regardless of PDO::ATTR_ERRMODE.
NOTE: TINYINT columns are frequently used as boolean columns which is the reason for
PDO::PARAM_BOOL.
Test script:
---------------
CREATE TABLE
s.a (
col tinyint(4) NOT NULL DEFAULT '0'
) ENGINE=InnoDB
$pdo = new PDO("mysql:localhost", "username", "password");
$stmt = $pdo->prepare("INSERT INTO s.a (col) VALUES (?)");
$stmt->bindValue(1, 0, PDO::PARAM_BOOL);
assertFalse($stmt->execute());
$errorInfo = $stmt->errorInfo();
assertEquals($errorInfo, ["00000", NULL, NULL]);
Expected result:
----------------
I expect PDO to throw an exception when PDO::ATTR_ERRMODE is PDO::ERRMODE_EXCEPTION instead of
silently returning false from PDOStatement::execute().
Actual result:
--------------
PDOStatement::execute() sucessfully determines that the statement did not succeed (returns false).
However, it does not throw an Exception despite PDO::ATTR_ERRMODE is set to PDO::ERRMODE_EXCEPTION
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=71059&edit=1