mysqli::commit
mysqli::commit
mysqli_commit
(PHP 5, PHP 7)
mysqli :: commit - mysqli_commit - 提交当前事务
描述
面向对象的风格
bool mysqli::commit ([ int $flags [, string $name ]] )
程序风格
bool mysqli_commit ( mysqli $link [, int $flags [, string $name ]] )
提交数据库连接的当前事务。
参数
`link`
仅过程样式:由mysqli_connect()或mysqli_init()返回的链接标识符
flags
MYSQLI_TRANS_COR_*
常量的位掩码。
name
如果提供,则执行COMMIT / * name * /
。
返回值
成功返回TRUE或失败时返回FALSE。
更新日志
版 | 描述 |
---|---|
5.5.0 | 添加标志和名称参数。 |
例子
示例#1 mysqli :: commit()示例
面向对象的风格
<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world"
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error()
exit(
}
$mysqli->query("CREATE TABLE Language LIKE CountryLanguage"
/* set autocommit to off */
$mysqli->autocommit(FALSE
/* Insert some values */
$mysqli->query("INSERT INTO Language VALUES ('DEU', 'Bavarian', 'F', 11.2)"
$mysqli->query("INSERT INTO Language VALUES ('DEU', 'Swabian', 'F', 9.4)"
/* commit transaction */
if (!$mysqli->commit()) {
print("Transaction commit failed\n"
exit(
}
/* drop table */
$mysqli->query("DROP TABLE Language"
/* close connection */
$mysqli->close(
?>
程序风格
<?php
$link = mysqli_connect("localhost", "my_user", "my_password", "test"
/* check connection */
if (!$link) {
printf("Connect failed: %s\n", mysqli_connect_error()
exit(
}
/* set autocommit to off */
mysqli_autocommit($link, FALSE
mysqli_query($link, "CREATE TABLE Language LIKE CountryLanguage"
/* Insert some values */
mysqli_query($link, "INSERT INTO Language VALUES ('DEU', 'Bavarian', 'F', 11.2)"
mysqli_query($link, "INSERT INTO Language VALUES ('DEU', 'Swabian', 'F', 9.4)"
/* commit transaction */
if (!mysqli_commit($link)) {
print("Transaction commit failed\n"
exit(
}
/* close connection */
mysqli_close($link
?>
扩展内容
- mysqli_autocommit() - 打开或关闭自动提交数据库修改
- mysqli_begin_transaction() - 启动一个事务
- mysqli_rollback() - 回滚当前事务
- mysqli_savepoint() - 设置一个指定的事务保存点
← mysqli::close
mysqli::$connect_errno →