关闭自动提交,进行一些查询,然后提交查询:
<?php
$mysqli = new mysqli("localhost","my_user","my_password","my_db");
if ($mysqli -> connect_errno) {
echo "Failed to connect to MySQL: " . $mysqli -> connect_error;
exit();
}
// Turn autocommit off
$mysqli -> autocommit(FALSE);
// Insert some values
$mysqli -> query("INSERT INTO Persons (FirstName,LastName,Age)
VALUES ('Peter','Griffin',35)");
$mysqli -> query("INSERT INTO Persons (FirstName,LastName,Age)
VALUES ('Glenn','Quagmire',33)");
// Commit transaction
if (!$mysqli -> commit()) {
echo "Commit transaction failed";
exit();
}
$mysqli -> close();
?>
查看底部的程序样式示例。
commit() / mysqli_commit() 函数提交指定数据库连接的当前事务。
提示:另请参阅自动提交()函数,打开或关闭自动提交数据库修改,以及回滚()函数,回滚当前事务。
$mysqli -> commit(
flags, name)
mysqli_commit(
connection, flags, name)
Parameter | Description |
---|---|
connection | Required. Specifies the MySQL connection to use |
flags | Optional. A constant:
|
name | Optional. COMMIT/*name*/ is executed if this parameter is specified |
返回值: | 成功则为真。失败时为 FALSE |
---|---|
PHP 版本: | 5+ |
PHP 变更日志: | PHP 5.5:添加了旗帜和姓名参数 |
关闭自动提交,进行一些查询,然后提交查询:
<?php
$con=mysqli_connect("localhost","my_user","my_password","my_db");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
exit;
}
// Turn autocommit 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
if (!mysqli_commit($con)) {
echo "Commit transaction failed";
exit();
}
// Close connection
mysqli_close($con);
?>
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!