PHP mysqli_rollback() 函数
2018-12-08 17:46 更新
PHP mysqli_rollback() 函数
实例
关闭自动提交,做一些查询,提交查询,然后回滚当前事务:
<?php
$con=mysqli_connect("localhost","my_user","my_password","my_db");
// Check connection
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 Persons (FirstName,LastName,Age)
VALUES ('Peter','Griffin',35)");
mysqli_query($con,"INSERT INTO Persons (FirstName,LastName,Age)
VALUES ('Glenn','Quagmire',33)");
// Commit transaction
mysqli_commit($con);
// Rollback transaction
mysqli_rollback($con);
// Close connection
mysqli_close($con);
?>
$con=mysqli_connect("localhost","my_user","my_password","my_db");
// Check connection
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 Persons (FirstName,LastName,Age)
VALUES ('Peter','Griffin',35)");
mysqli_query($con,"INSERT INTO Persons (FirstName,LastName,Age)
VALUES ('Glenn','Quagmire',33)");
// Commit transaction
mysqli_commit($con);
// Rollback transaction
mysqli_rollback($con);
// Close connection
mysqli_close($con);
?>
定义和用法
mysqli_rollback() 函数回滚指定数据库连接的当前事务。
提示:请查看 mysqli_commit() 函数,用于提交指定数据库连接的当前事务。请查看 mysqli_autocommit() 函数,用于开启或关闭自动提交数据库修改。
语法
mysqli_rollback(connection);
参数 | 描述 |
---|---|
connection | 必需。规定要使用的 MySQL 连接。 |
技术细节
返回值: | 如果成功则返回 TRUE,如果失败则返回 FALSE。 |
---|---|
PHP 版本: | 5+ |
PHP mysqli 参考手册
以上内容是否对您有帮助:
更多建议: