PHP mysqli_rollback() function is used to rollbacks the current transaction for the database. The mysqli_autocommit() function turns on or off auto-committing database.
Syntax
bool mysqli_rollback(connection, flags);
Parameter | Description |
---|---|
connection : | Required parameter. The MySQL connection to be used |
flags : | Required parameter. A bitmask of MYSQLI_TRANS_COR_* constants. |
Return Values : | Returns TRUE on success or FALSE on failure. |
<?php $con = mysqli_connect("localhost","user","password","db"); if (mysqli_connect_errno()) { 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 employee (name) VALUES ('James')"); mysqli_query($con,"INSERT INTO employee (name) VALUES ('Rocky')"); // Commit transaction mysqli_commit($con); // Rollback transaction mysqli_rollback($con); mysqli_close($con); ?>