diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2020-10-20 11:29:47 +0200 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2020-10-26 17:01:18 +0100 |
commit | 7b9519a792a04d6943ff7082ff343a96ec00157f (patch) | |
tree | 6be4bfcec76cf2e7285deed4603f817a1e91a59a /ext/pdo_mysql/tests/pdo_mysql_commit.phpt | |
parent | 6d3695a217c8a3a295fc723a8bd079db05984b70 (diff) | |
download | php-git-7b9519a792a04d6943ff7082ff343a96ec00157f.tar.gz |
Fix inconsistency in PDO transaction state
This addresses an issue introduced by #4996 and reported in
https://bugs.php.net/bug.php?id=80260.
Now that PDO::inTransaction() reports the real transaction state
of the connection, there may be a mismatch with PDOs internal
transaction state (in_tcx). This is compounded by the fact that
MySQL performs implicit commits for DDL queries.
This patch fixes the issue by making beginTransaction/commit/rollBack
work on the real transaction state provided by the driver as well
(or falling back to in_tcx if the driver does not support it).
This does mean that writing something like
$pdo->beginTransaction();
$pdo->exec('CREATE DATABASE ...');
$pdo->rollBack(); // <- illegal
will now result in an error, because the CREATE DATABASE already
committed the transaction. I believe this behavior is both correct
and desired -- otherwise, there is no indication that the code did
not behave correctly and the rollBack() was effectively ignored.
However, this is also a BC break.
Closes GH-6355.
Diffstat (limited to 'ext/pdo_mysql/tests/pdo_mysql_commit.phpt')
-rw-r--r-- | ext/pdo_mysql/tests/pdo_mysql_commit.phpt | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/ext/pdo_mysql/tests/pdo_mysql_commit.phpt b/ext/pdo_mysql/tests/pdo_mysql_commit.phpt index 506be6475f..f88ae149fa 100644 --- a/ext/pdo_mysql/tests/pdo_mysql_commit.phpt +++ b/ext/pdo_mysql/tests/pdo_mysql_commit.phpt @@ -23,9 +23,14 @@ if (false == MySQLPDOTest::detect_transactional_mysql_engine($db)) // DDL will issue an implicit commit $db->exec(sprintf('DROP TABLE IF EXISTS test_commit')); $db->exec(sprintf('CREATE TABLE test_commit(id INT) ENGINE=%s', MySQLPDOTest::detect_transactional_mysql_engine($db))); - if (true !== ($tmp = $db->commit())) { - printf("[002] No commit allowed? [%s] %s\n", - $db->errorCode(), implode(' ', $db->errorInfo())); + try { + $db->commit(); + $failed = false; + } catch (PDOException $e) { + $failed = true; + } + if (!$failed) { + printf("[002] Commit should have failed\n"); } // pdo_transaction_transitions should check this as well... |