Bug #79914 [NEW]: PHP PDO mysqlnd ignores InnoDB deadlock errors
| From: | houxiaoxian1111 at 163 dot com | Date: | Thu, 30 Jul 2020 06:58:38 +0000 |
| Subject: | Bug #79914 [NEW]: PHP PDO mysqlnd ignores InnoDB deadlock errors | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-228287@lists.php.net to get a copy of this message | ||
From: houxiaoxian1111 at 163 dot com
Operating system: centos 7.8.2003
PHP version: 7.2.32
Package: PDO MySQL
Bug Type: Bug
Bug description:PHP PDO mysqlnd ignores InnoDB deadlock errors
Description:
------------
PHP PDO mysqlnd ignores InnoDB deadlock errors (1213) when
ATTR_EMULATE_PREPARES = false
Test script:
---------------
CREATE DATABASE test CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci';
USE test;
CREATE TABLE test (
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
data MEDIUMTEXT NULL
) ENGINE = InnoDB;
<?php
$password = 'password';
$dbh = new \PDO("mysql:host=localhost;dbname=test", 'root', $password,
[\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
\PDO::ATTR_EMULATE_PREPARES => false]);
$dbh->query('SET TRANSACTION ISOLATION LEVEL SERIALIZABLE');
$dbh->beginTransaction();
$dbh->prepare("INSERT INTO test (data) VALUES (:data);")
->execute(['data' => 'a']);
sleep(5);
$sth = $dbh->prepare("SELECT id, data FROM test WHERE 1");
var_dump($sth->execute(), $sth->fetchAll(), $dbh->commit());
Expected result:
----------------
Shell 1:
[jan@localhost ~]$ php test.php
bool(true)
array(1) {
[0] =>
array(4) {
'id' =>
int(1)
[0] =>
int(1)
'data' =>
string(1) "a"
[1] =>
string(1) "a"
}
}
bool(true)
Shell 2: (started 2 seconds after 1st)
[jan@localhost ~]$ php test.php
PHP Fatal error: Uncaught PDOException: SQLSTATE[40001]: Serialization
failure: 1213 Deadlock found when trying to get lock; try restarting
transaction in /home/jan/test.php:16
Stack trace:
#0 /home/jan/test.php(16): PDOStatement->execute()
#1 {main}
thrown in /home/jan/test.php on line 16
Actual result:
--------------
Shell 1:
[jan@localhost ~]$ php test.php
bool(true)
array(1) {
[0] =>
array(4) {
'id' =>
int(1)
[0] =>
int(1)
'data' =>
string(1) "a"
[1] =>
string(1) "a"
}
}
bool(true)
Shell 2: (started 2 seconds after 1st)
[jan@localhost ~]$ php test.php
bool(true)
array(0) {
}
bool(true)
--
Edit bug report at https://bugs.php.net/bug.php?id=79914&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=79914&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=79914&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=79914&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=79914&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=79914&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=79914&r=support
Expected behavior: https://bugs.php.net/fix.php?id=79914&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=79914&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=79914&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=79914&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=79914&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=79914&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=79914&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=79914&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=79914&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=79914&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=79914&r=mysqlcfg