Bug #81533 [Opn]: mysqli_rollback() returns TRUE if there's no active transaction

From: Date: Tue, 19 Oct 2021 19:54:36 +0000
Subject: Bug #81533 [Opn]: mysqli_rollback() returns TRUE if there's no active transaction
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-237290@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=81533&edit=1

 ID:                 81533
 User updated by:    morozov at tut dot by
 Reported by:        morozov at tut dot by
 Summary:            mysqli_rollback() returns TRUE if there's no active
                     transaction
 Status:             Open
 Type:               Bug
 Package:            MySQLi related
 Operating System:   Linux
 PHP Version:        8.1.0RC4
 Block user comment: N
 Private report:     N

 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------
[2021-10-17 21:01:46] 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)


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=81533&edit=1


Thread (2 messages)

« previous php.bugs (#237290) next »