PHP mysqli_rollback()Functions
Turn off auto-commit, do some queries, commit the query, then roll back the current transaction:
<?php
// 假定数据库用户名:root,密码:123456,数据库:EXAMPLE
$con=mysqli_connect("localhost","root","123456","EXAMPLE");
if (mysqli_connect_errno($con))
{
echo "连接 MySQL 失败: " . mysqli_connect_error();
}
// 关闭自动提交
mysqli_autocommit($con,FALSE);
// 插入数据
mysqli_query($con,"INSERT INTO websites (name, url, alexa, country)
VALUES ('百度','https://www.baidu.com/','4','CN')");
mysqli_query($con,"INSERT INTO websites (name, url, alexa, country)
VALUES (Facebook','https://www.facebook.com/','2','USA')");
// 提交事务
mysqli_commit($con);
//回滚事务
mysqli_rollback($con);
// 关闭连接
mysqli_close($con);
?>
Definition and Usage
The mysqli_rollback() function rolls back the current transaction for the specified database connection.
Tip:Please seemysqli_commit() function, used to commit the current transaction for the specified database connection. Please see mysqli_autocommit()function, used to turn on or off auto-commit of database modifications.
Syntax
mysqli_rollback(connection);
| Parameters | Description |
|---|---|
| connection | Required. Specifies the MySQL connection to use. |
Technical Details
| Return value: | Returns TRUE on success, FALSE on failure. |
|---|---|
| PHP Version: | 5+ |
PHP mysqli Reference Manual Other Extensions