cubrid_commit

(PECL CUBRID >= 8.3.0)

cubrid_commit提交事务

描述

cubrid_commit(resource $conn_identifier): bool

cubrid_commit() 函数用于对由 conn_identifier 指示的当前正在进行的事务执行提交操作。调用 cubrid_commit() 函数后,与服务器的连接将关闭;但是,连接句柄仍然有效。

在 CUBRID PHP 中,默认情况下,事务管理的自动提交模式被禁用。您可以使用 cubrid_set_autocommit() 设置它。您可以使用 cubrid_get_autocommit() 获取其状态。在您开始事务之前,请务必禁用自动提交模式。

参数

conn_identifier

连接标识符。

返回值

成功时返回 true,失败时返回 false

示例

示例 #1 cubrid_commit() 示例

<?php
$conn
= cubrid_connect("localhost", 33000, "demodb", "dba");

@
cubrid_execute($conn, "DROP TABLE publishers");

$sql = <<<EOD
CREATE TABLE publishers(
pub_id CHAR(3),
pub_name VARCHAR(20),
city VARCHAR(15),
state CHAR(2),
country VARCHAR(15)
)
EOD;
cubrid_set_autocommit($conn,false);
if (!
cubrid_execute($conn, $sql)) {
printf("Error facility: %d\nError code: %d\nError msg: %s\n", cubrid_error_code_facility(), cubrid_error_code(), cubrid_error_msg());

cubrid_disconnect($conn);
exit;
}

$req = cubrid_prepare($conn, "INSERT INTO publishers VALUES(?, ?, ?, ?, ?)");

$id_list = array("P01", "P02", "P03", "P04");
$name_list = array("Abatis Publishers", "Core Dump Books", "Schadenfreude Press", "Tenterhooks Press");
$city_list = array("New York", "San Francisco", "Hamburg", "Berkeley");
$state_list = array("NY", "CA", NULL, "CA");
$country_list = array("USA", "USA", "Germany", "USA");

for (
$i = 0, $size = count($id_list); $i < $size; $i++) {
cubrid_bind($req, 1, $id_list[$i]);
cubrid_bind($req, 2, $name_list[$i]);
cubrid_bind($req, 3, $city_list[$i]);
cubrid_bind($req, 4, $state_list[$i]);
cubrid_bind($req, 5, $country_list[$i]);

if (!(
$ret = cubrid_execute($req))) {
break;
}
}

if (!
$ret) {
cubrid_rollback($conn);
} else {
cubrid_commit($conn);

$req = cubrid_execute($conn, "SELECT * FROM publishers");
while (
$result = cubrid_fetch_assoc($req)) {
printf("%-3s %-20s %-15s %-3s %-15s\n",
$result["pub_id"], $result["pub_name"], $result["city"], $result["state"], $result["country"]);
}
}

cubrid_disconnect($conn);
?>

上面的示例将输出

P01 Abatis Publishers    New York        NY  USA            
P02 Core Dump Books      San Francisco   CA  USA            
P03 Schadenfreude Press  Hamburg             Germany        
P04 Tenterhooks Press    Berkeley        CA  USA

参见

添加说明

用户贡献的说明

此页面没有用户贡献的笔记。
To Top