Bug #77163 [Opn->Ver]: PDOException not thrown for SELECT FOR UPDATE with ATTR_EMULATE_PREPARES = 0

From: Date: Wed, 22 Apr 2020 07:04:57 +0000
Subject: Bug #77163 [Opn->Ver]: PDOException not thrown for SELECT FOR UPDATE with ATTR_EMULATE_PREPARES = 0
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-226708@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77163&edit=1 ID: 77163 Updated by: sjon@php.net Reported by: contact at bastiaangrutters dot nl Summary: PDOException not thrown for SELECT FOR UPDATE with ATTR_EMULATE_PREPARES = 0 -Status: Open +Status: Verified Type: Bug Package: PDO MySQL Operating System: Linux -PHP Version: 7.2.12 +PHP Version: 7.4.5 Block user comment: N Private report: N New Comment: this is still broken Previous Comments: ------------------------------------------------------------------------ [2018-11-15 12:28:36] contact at bastiaangrutters dot nl Description: ------------ When using PDO MySQL to select rows for update with PDO::ATTR_EMULATE_PREPARES set to false and PDO::ATTR_ERRMODE set to PDO::ERRMODE_EXCEPTION no exception is thrown when the rows are already locked and a timeout occurs. Note: The exception is thrown when PDO::ATTR_EMULATE_PREPARES is not set/set to true or when a parameter is used in the select query. Instructions on reproducing this: Open mysql on cli, and perform queries: CREATE DATABASE testdb; USE testdb; CREATE TABLE test (id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, value VARCHAR(30) NOT NULL); INSERT INTO test (value) VALUES ('test'); # Before starting the test script open a transaction and lock the table: BEGIN; SELECT * FROM test FOR UPDATE; # Now run the script Test script: --------------- <?php $pdo = new PDO('mysql:dbname=testdb;host=localhost', 'username', 'password'); $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $pdo->beginTransaction(); $statement = $pdo->prepare('SELECT * FROM test FOR UPDATE'); $statement->execute(); var_dump( $statement->fetchAll(), $statement->errorCode() ); $pdo->commit(); Expected result: ---------------- Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restarting transaction in test-pdo.php:14 Stack trace: #0 test-pdo.php(14): PDOStatement->execute() #1 {main} thrown in test-pdo.php on line 14 Actual result: -------------- array(0) { } string(5) "00000" ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=77163&edit=1

« previous php.bugs (#226708) next »