aci_rollback

aci_rollback — 回滚未提交的事务

说明

aci_rollback(resource $connection): bool

aci_rollback() 回滚 数据库 连接 connection 上所有未提交的语句。

成功时返回 true, 或者在失败时返回 false。

注意:
当关闭连接或脚本结束时(看哪个先)事务会自动回卷。需要明确地调用 aci_commit() 来提交事务,或 aci_rollback() 来中止事务。
注意:
在 PHP 5.0.0 之前的版本必须使用 acirollback() 替代本函数。该函数名仍然可用,
为向下兼容作为 aci_rollback() 的别名。不过其已被废弃,不推荐使用。

参数

connection

数据库连接标识符,由 aci_connect()aci_new_connect() 返回。

返回值

成功时返回 true, 或者在失败时返回 false。

范例

示例 #1 aci_rollback()示例

<?php

// Insert into several tables, rolling back the changes if an error occurs

$conn = aci_connect('sysdba', 'szoscar55', 'localhost:2003/OSRDB');

$stid = aci_parse($conn, "INSERT INTO mysalary (id, name) VALUES (1, 'Chris')");

// The aci_NO_AUTO_COMMIT flag tells Oracle not to commit the INSERT immediately
// Use aci_DEFAULT as the flag for PHP <= 5.3.1.  The two flags are equivalent
$r = aci_execute($stid, aci_NO_AUTO_COMMIT);
if (!$r) {
        $e = aci_error($stid);
        trigger_error(htmlentities($e['message']), E_USER_ERROR);
}

$stid = aci_parse($conn, 'INSERT INTO myschedule (startday) VALUES (12)');
$r = aci_execute($stid, aci_NO_AUTO_COMMIT);
if (!$r) {
        $e = aci_error($stid);
        aci_rollback($conn);  // rollback changes to both tables
        trigger_error(htmlentities($e['message']), E_USER_ERROR);
}

// Commit the changes to both tables
$r = aci_commit($conn);
if (!r) {
        $e = aci_error($conn);
        trigger_error(htmlentities($e['message']), E_USER_ERROR);
}

?>

示例 #2回滚到SAVEPOINT示例

<?php
$stid = aci_parse($conn, 'UPDATE mytab SET id = 1111');
aci_execute($stid, aci_NO_AUTO_COMMIT);

// Create the savepoint
$stid = aci_parse($conn, 'SAVEPOINT mysavepoint');
aci_execute($stid, aci_NO_AUTO_COMMIT);

$stid = aci_parse($conn, 'UPDATE mytab SET id = 2222');
aci_execute($stid, aci_NO_AUTO_COMMIT);

// Use an explicit SQL statement to rollback to the savepoint
$stid = aci_parse($conn, 'ROLLBACK TO SAVEPOINT mysavepoint');
aci_execute($stid, aci_NO_AUTO_COMMIT);

aci_commit($conn);  // mytab now has id of 1111
?>

注释

注意:
当您关闭连接或脚本结束时(以最快者为准),事务会自动回滚。您需要显式调用`aci_commit() <aci_commit>`来提交事务。

显式或默认情况下使用aci_COMMIT_ON_SUCCESS模式的对`aci_execute() <aci_execute>`的任何调用都将提交任何以前未提交的事务。

任何DDL语句(如CREATE或DROP)都将自动提交任何未提交的事务。
注意:
在5.0.0之前的PHP版本中,必须改用ocirollback() <ocirollback>`。

参见

aci_commit()- 提交未执行的事务处理

aci_execute()- 执行一条语句