|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 02:00:01 2025 UTC |
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.