php.net |  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
Description:
------------
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:

<?php

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

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


Expected result:
----------------
bool(false)

Actual result:
--------------
bool(true)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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

<?php

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)
var_dump(mysqli_rollback($conn));
// bool(true)
$result = mysqli_query($conn, 'SELECT id FROM txn_test');
var_dump(mysqli_fetch_row($result));
// 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-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 17:01:30 2024 UTC