aci_commit

aci_commit — 提交未执行的事务处理

说明

aci_commit(resource $connection): bool

aci_commit() 将 数据库 连接 connection 上正在运行的事务中所有未执行的语句提交处理。

示例 #1 aci_commit() 例子

<?php
    // Login to db server
    $conn = aci_connect('scott', 'tiger');

    // Parse SQL
    $stmt = aci_parse($conn, "
                              INSERT INTO
                                         employees (name, surname)
                                   VALUES
                                         ('Maxim', 'Maletsky')
                             ");

    /* Execute statement
       aci_DEFAULT tells aci_execute()
       not to commit statement immediately */
    aci_execute($stmt, aci_DEFAULT);

    /*
    ....
    Parsing and executing other statements here ...
    ....
    */

    // Commit transaction
    $committed = aci_commit($conn);

    // Test whether commit was successful. If error occurred, return error message
    if (!$committed) {
        $error = aci_error($conn);
        echo 'Commit failed. Oracle reports: ' . $error['message'];
    }

?>

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

警告

注意: 当关闭连接或脚本结束时(看哪个先)事务会自动回卷。需要明确地调用 aci_commit() 来提交事务,或 aci_rollback() 来中止事务。

警告

注意: 在 PHP 5.0.0 之前的版本必须使用 acicommit() 替代本函数。该函数名仍然可用,为向下兼容作为 aci_commit() 的别名。不过其已被废弃,不推荐使用。

参见 aci_rollback() 和 aci_execute()。

参数

connection An Oracle connection identifier, returned by aci_connect(), aci_pconnect(), or aci_new_connect().

返回值

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

范例

示例 #2 aci_commit() example

<?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);
}

?>

注释

警告

当您关闭连接或脚本结束时(以最快者为准),事务将自动回滚。您需要显式调用aci_commit()来提交事务。 显式或默认情况下,对aci_execute()的任何调用都将提交任何以前未提交的事务。 任何DDL语句(如CREATE或DROP)都将自动提交任何未提交的事务。

警告

在5.0.0之前的PHP版本中,必须改用acicommit()。

参见

aci_execute()- 执行一条语句

aci_rollback()- 回滚未提交的事务