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: 2020-12-11 15:06 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: Duplicate Package: PDO MySQL
PHP Version: 5.6.16 OS: Windows 8.1 Enterprise
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
46 - 33 = ?
Subscribe to this entry?

 
 [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
 [2020-12-11 15:06 UTC] nikic@php.net
-Status: Open +Status: Duplicate
 [2020-12-11 15:06 UTC] nikic@php.net
Same issue as bug #66632, which has been fixed for a while already.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 07:01:28 2024 UTC