The mysqli_rollback() function rolls back the current transaction for the specified database connection.
PHP mysqli_rollback() Function has the following syntax.
Object oriented style
bool mysqli::rollback ([ int $flags [, string $name ]] )
Procedural style
bool mysqli_rollback ( mysqli $link [, int $flags [, string $name ]] )
It returns TRUE on success. FALSE on failure.
The mysqli_commit() function commits the current transaction for the specified database connection.
The mysqli_autocommit() function turns on or off auto-committing database.
<?php/* www . j a va 2 s . c o m*/
$con=mysqli_connect("localhost","my_user","my_password","my_db");
if (mysqli_connect_errno($con)){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// Set autocommit to off
mysqli_autocommit($con,FALSE);
// Insert some values
mysqli_query($con,"INSERT INTO emp (name)VALUES ('Java')");
mysqli_query($con,"INSERT INTO emp (name)VALUES ('PHP')");
// Commit transaction
mysqli_commit($con);
// Rollback transaction
mysqli_rollback($con);
mysqli_close($con);
?>