OCI8 関数
PHP Manual

oci_commit

(PHP 5, PECL OCI8 >= 1.1.0)

oci_commit未解決のトランザクションをコミットする

説明

bool oci_commit ( resource $connection )

Oracle接続connection 上の未解決なトランザクションをコミットします。 コミットすると、現在のトランザクションを終了してすべての変更を確定させます。 また、保持しているロックをすべて解放します。

A transaction begins when the first SQL statement that changes data is executed with oci_execute() using the OCI_NO_AUTO_COMMIT flag. Further data changes made by other statements become part of the same transaction. Data changes made in a transaction are temporary until the transaction is committed or rolled back. Other users of the database will not see the changes until they are committed.

When inserting or updating data, using transactions is recommended for relational data consistency and for performance reasons.

パラメータ

connection

oci_connect()oci_pconnect() あるいは oci_new_connect() が返す Oracle 接続 ID。

返り値

成功した場合に TRUE を、失敗した場合に FALSE を返します。

例1 oci_commit() の例

<?php

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

$conn oci_connect('hr''welcome''localhost/XE');

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

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

$stid oci_parse($conn'INSERT INTO myschedule (startday) VALUES (12)');
$r oci_execute($stidOCI_NO_AUTO_COMMIT);
if (!
$r) {    
    
$e oci_error($stid);
    
oci_rollback($conn);  // rollback changes to both tables
    
trigger_error(htmlentities($e['message']), E_USER_ERROR);
}

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

?>

注意

注意: トランザクションは接続を閉じたとき、 もしくはスクリプトの終了時のいずれの場合でも すぐに自動的にロールバックされます。 トランザクションをコミットするには oci_commit() をコールする必要があります。
Any call to oci_execute() that uses OCI_COMMIT_ON_SUCCESS mode explicitly or by default will commit any previous uncommitted transaction.
Any Oracle DDL statement such as CREATE or DROP will automatically commit any uncommitted transaction.

注意: In PHP versions before 5.0.0 you must use ocicommit() instead. 現在のバージョンでは、古い関数名もまだ使えます。 しかし、これは廃止予定であり非推奨です。

参考


OCI8 関数
PHP Manual