Bug #80924 [Com]: PDO: Begin transaction plus lock table fail

From: Date: Wed, 31 Mar 2021 20:39:13 +0000
Subject: Bug #80924 [Com]: PDO: Begin transaction plus lock table fail
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-233111@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80924&edit=1 ID: 80924 Comment by: danack@php.net Reported by: pau dot ferran dot grau at gmail dot com Summary: PDO: Begin transaction plus lock table fail Status: Open Type: Bug Package: PDO MySQL Operating System: All PHP Version: 8.0.3 Block user comment: N Private report: N New Comment: Reading the manual, I think your code may be wrong: https://dev.mysql.com/doc/refman/8.0/en/lock-tables.html#lock-tables-and-transactions "LOCK TABLES is not transaction-safe and implicitly commits any active transaction before attempting to lock the tables." So you'd need to beginTransaction after the lock tables, would be my guess. Previous Comments: ------------------------------------------------------------------------ [2021-03-31 20:31:27] levim@php.net I am not an expert in databases. Based on my reading of the docs, transactions and locking are not particularly compatible: https://dev.mysql.com/doc/refman/8.0/en/lock-tables.html#lock-tables-and-transactions ------------------------------------------------------------------------ [2021-03-31 20:20:55] pau dot ferran dot grau at gmail dot com Description: ------------ when I begin a transaction and I try lock a table then pdo throw the exception with the message: There is no active transaction. I use a MySQL 5.7.20 Test script: --------------- try { $dbh = new \PDO('mysql:host=127.0.0.1;port=3309;dbname=event_sourcing_test', 'root', null); $dbh->beginTransaction(); $dbh->exec('LOCK TABLE test WRITE'); $dbh->exec("INSERT INTO test (id) VALUES ('a')"); $dbh->commit(); $dbh->exec('UNLOCK TABLES'); } catch (\PDOException $e) { echo $e->getMessage() . PHP_EOL; //There is no active transaction } Expected result: ---------------- Pdo doesn't throw an exception Actual result: -------------- Pdo throws an exception PDOException Object ( [message:protected] => There is no active transaction [string:Exception:private] => [code:protected] => 0 [file:protected] => /Users/pau/Projects/apps/event-sourcing/test.php [line:protected] => 10 [trace:Exception:private] => Array ( [0] => Array ( [file] => /Users/pau/Projects/apps/event-sourcing/test.php [line] => 10 [function] => commit [class] => PDO [type] => -> [args] => Array ( ) ) ) [previous:Exception:private] => [errorInfo] => ) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=80924&edit=1

« previous php.bugs (#233111) next »