php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77163 PDOException not thrown for SELECT FOR UPDATE with ATTR_EMULATE_PREPARES = 0
Submitted: 2018-11-15 12:28 UTC Modified: -
Votes:2
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: contact at bastiaangrutters dot nl Assigned:
Status: Open Package: PDO MySQL
PHP Version: 7.2.12 OS: Linux
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: contact at bastiaangrutters dot nl
New email:
PHP Version: OS:

 

 [2018-11-15 12:28 UTC] 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"

Patches

Add a Patch

Pull Requests

Add a Pull Request

 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Mon Dec 10 08:01:24 2018 UTC