php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71059 Undetected error in PDO when INSERTing with PARAM_BOOL
Submitted: 2015-12-08 12:09 UTC Modified: 2015-12-08 12:12 UTC
Votes:4
Avg. Score:4.0 ± 1.0
Reproduced:3 of 3 (100.0%)
Same Version:2 (66.7%)
Same OS:0 (0.0%)
From: tobias dot marstaller at enlifor dot com Assigned:
Status: Open Package: PDO MySQL
PHP Version: 5.6.16 OS: Windows 8.1 Enterprise
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: tobias dot marstaller at enlifor dot com
New email:
PHP Version: OS:

 

 [2015-12-08 12:09 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-12-08 12:12 UTC] tobias dot marstaller at enlifor dot com
-Summary: Undetected error in PDO +Summary: Undetected error in PDO when INSERTing with PARAM_BOOL
 [2015-12-08 12:12 UTC] tobias dot marstaller at enlifor dot com
Clarified bug title
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sun Aug 09 17:01:23 2020 UTC