|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[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
[2020-12-11 15:06 UTC] nikic@php.net
-Status: Open
+Status: Duplicate
[2020-12-11 15:06 UTC] nikic@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Dec 05 16:00:02 2025 UTC |
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