|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81533 mysqli_rollback() returns TRUE if there's no active transaction
Submitted: 2021-10-17 21:01 UTC Modified: 2021-10-19 19:54 UTC
From: morozov at tut dot by Assigned:
Status: Open Package: MySQLi related
PHP Version: 8.1.0RC4 OS: Linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2021-10-17 21:01 UTC] morozov at tut dot by
mysqli_rollback() called on a fresh connection (while autocommit is ON) returns TRUE, although there's no active transaction. This contradicts the documentation which states:
> Returns true on success or false on failure.

It's also inconsistent with pdo_mysql which reports such an attempt as invalid:


(new PDO('mysql:host=;dbname=mysql', 'root', ''))->rollback();
// PDOException: There is no active transaction

Test script:
var_dump(mysqli_connect('', 'root', '', 'mysql')->rollback());

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-10-19 19:54 UTC] morozov at tut dot by
A more realistic example:


var_dump(mysqli_query($conn, 'DROP TABLE IF EXISTS txn_test'));
// bool(true)
var_dump(mysqli_query($conn, 'CREATE TABLE txn_test(id INT)'));
// bool(true)
var_dump(mysqli_autocommit($conn, false));
// bool(true)
var_dump(mysqli_query($conn, 'INSERT INTO txn_test VALUES (42)'));
// bool(true)
var_dump(mysqli_query($conn, 'DROP TABLE IF EXISTS blah'));
// bool(true)
// bool(true)
$result = mysqli_query($conn, 'SELECT id FROM txn_test');
// array(1) {
//     [0] =>
//     string(2) "42"
// }

After the `DROP TABLE IF EXISTS` statement, MySQL implicitly commits the transaction but the driver still reports the rollback as a success.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Wed Nov 29 10:01:27 2023 UTC