PHP mysqli_rollback () function
Turn off auto-commit, do some queries, submit the query, and then roll back the current transaction:
<?php // 假定数据库用户名:root,密码:123456,数据库:w3big $con=mysqli_connect("localhost","root","123456","w3big"); 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
mysqli_rollback () function to roll back the current transaction specified database connection.
Tip: Check out mysqli_commit () function is used to commit the current transaction specified database connection. See the mysqli_autocommit () function is used to enable or disable auto-commit database changes.
grammar
mysqli_rollback( connection ) ;
参数 | 描述 |
---|---|
connection | 必需。规定要使用的 MySQL 连接。 |
technical details
return value: | If successful it returns TRUE, on failure returns FALSE. |
---|---|
PHP version: | 5+ |
PHP mysqli Reference Manual