Turn off autocommit, do some queries, commit the queries, then roll back the current transaction:
<?php // Assume database username: root, password: 123456, database: CODERCTO $con=mysqli_connect("localhost","root","123456","CODERCTO"); if (mysqli_connect_errno($con)) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } // Turn off automatic submission 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);//Rollback transaction mysqli_rollback($con );//Close the connection mysqli_close($con);?>
The mysqli_rollback() function rolls back the current transaction for the specified database connection.
Tip: See the mysqli_commit() function, which commits the current transaction for a specified database connection. Please see the mysqli_autocommit() function, which is used to turn on or off automatic commit of database modifications.
mysqli_rollback( connection ) ;
parameter | describe |
---|---|
connection | Required. Specifies the MySQL connection to use. |
Return value: | Returns TRUE if successful and FALSE if failed. |
---|---|
PHP version: | 5+ |