Easy Tutorial
❮ Func String Parse Str Func Xml Parser Get Option ❯

PHP mysqli_rollback() Function

PHP mysqli Reference Manual

Disable auto-commit, perform some queries, commit the queries, and then roll back the current transaction:

<?php 
// Assume database username: root, password: 123456, database: tutorialpro 
$con = mysqli_connect("localhost", "root", "123456", "tutorialpro"); 
if (mysqli_connect_errno($con)) 
{ 
    echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
} 

// Disable auto-commit
mysqli_autocommit($con, FALSE);

// Insert data
mysqli_query($con, "INSERT INTO websites (name, url, alexa, country)
VALUES ('Baidu', 'https://www.baidu.com/', '4', 'CN')");
mysqli_query($con, "INSERT INTO websites (name, url, alexa, country)
VALUES ('Facebook', 'https://www.facebook.com/', '2', 'USA')");

// Commit transaction
mysqli_commit($con);

// Roll back transaction
mysqli_rollback($con);

// Close connection
mysqli_close($con);
?>

Definition and Usage

The mysqli_rollback() function rolls back the current transaction for the specified database connection.

Tip: See the mysqli_commit() function to commit the current transaction for the specified database connection. See the mysqli_autocommit() function to turn on or off auto-commit of database modifications.


Syntax

Parameter Description
connection Required. Specifies the MySQL connection to use.

Technical Details

Return Value: Returns TRUE on success, FALSE on failure.
PHP Version: 5+
--- ---

❮ Func String Parse Str Func Xml Parser Get Option ❯