oci_commit

(PHP 5, PHP 7, PECL OCI8 >= 1.1.0)

oci_commit锟结交未执锟叫碉拷锟斤拷锟斤拷锟斤拷

说锟斤拷

oci_commit ( resource $connection ) : bool

oci_commit() 锟斤拷 Oracle 锟斤拷锟斤拷 connection 锟斤拷锟斤拷锟斤拷锟斤拷锟叫碉拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷未执锟叫碉拷锟斤拷锟斤拷峤伙拷锟斤拷锟�

Example #1 oci_commit() 锟斤拷锟斤拷

<?php
    
// Login to Oracle server
    
$conn oci_connect('scott''tiger');

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

    
/* Execute statement
       OCI_DEFAULT tells oci_execute()
       not to commit statement immediately */
    
oci_execute($stmtOCI_DEFAULT);

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

    // Commit transaction
    
$committed oci_commit($conn);

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

?>

锟缴癸拷时锟斤拷锟斤拷 TRUE锟斤拷 锟斤拷锟斤拷锟斤拷失锟斤拷时锟斤拷锟斤拷 FALSE锟斤拷

Note:

锟斤拷锟截憋拷锟斤拷锟接伙拷疟锟斤拷锟斤拷锟绞憋拷锟斤拷锟斤拷母锟斤拷龋锟斤拷锟斤拷锟斤拷锟皆讹拷锟截撅拷锟斤拷要锟斤拷确锟截碉拷锟斤拷 oci_commit() 锟斤拷锟结交锟斤拷锟今,伙拷 oci_rollback() 锟斤拷锟斤拷止锟斤拷锟斤拷

Note:

锟斤拷 PHP 5.0.0 之前锟侥版本锟斤拷锟斤拷使锟斤拷 ocicommit() 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷煤锟斤拷锟斤拷锟斤拷锟饺伙拷锟斤拷茫锟轿拷锟斤拷录锟斤拷锟斤拷锟轿� oci_commit() 锟侥憋拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟窖憋拷锟斤拷锟斤拷锟斤拷锟斤拷锟狡硷拷使锟矫★拷

锟轿硷拷 oci_rollback() 锟斤拷 oci_execute()锟斤拷

锟斤拷锟斤拷

connection

An Oracle connection identifier, returned by oci_connect(), oci_pconnect(), or oci_new_connect().

锟斤拷锟斤拷值

锟缴癸拷时锟斤拷锟斤拷 TRUE锟斤拷 锟斤拷锟斤拷锟斤拷失锟斤拷时锟斤拷锟斤拷 FALSE锟斤拷

锟斤拷锟斤拷

Example #2 oci_commit() example

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

?>

注锟斤拷

Note:

Transactions are automatically rolled back when you close the connection, or when the script ends, whichever is soonest. You need to explicitly call oci_commit() to commit the transaction.

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.

Note:

In PHP versions before 5.0.0 you must use ocicommit() instead. 锟节碉拷前锟芥本锟叫o拷锟缴的猴拷锟斤拷锟斤拷锟斤拷锟斤拷锟皆憋拷使锟矫o拷锟斤拷锟窖撅拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷使锟矫★拷

锟轿硷拷