Description

After execution, statements like INSERT will
have data committed to the database by default. For statements
like SELECT, execution performs the logic of the
query. Query results can subsequently be fetched in PHP with
functions like oci_fetch_array().

Each parsed statement may be executed multiple times, saving the
cost of re-parsing. This is commonly used
for INSERT statements when data is bound
with oci_bind_by_name().

Parameters

statement

A valid OCI statement identifier.

mode

An optional second parameter can be one of the following constants:

Execution Modes

Constant

Description

OCI_COMMIT_ON_SUCCESS

Automatically commit all outstanding changes for
this connection when the statement has succeeded. This
is the default.

Do not automatically commit changes. Prior to PHP
5.3.2 (PECL OCI8 1.4)
use OCI_DEFAULT which is equivalent
to OCI_NO_AUTO_COMMIT.

Using OCI_NO_AUTO_COMMIT mode starts or continues a
transaction. Transactions are automatically rolled back when
the connection is closed, or when the script ends. Explicitly
call oci_commit() to commit a transaction,
or oci_rollback() to abort it.

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

If OCI_NO_AUTO_COMMIT mode is used for any
statement including queries, and
oci_commit()
or oci_rollback() is not subsequently
called, then OCI8 will perform a rollback at the end of the
script even if no data was changed. To avoid an unnecessary
rollback, many scripts do not
use OCI_NO_AUTO_COMMIT mode for queries or
PL/SQL. Be careful to ensure the appropriate transactional
consistency for the application when
using oci_execute() with different modes in
the same script.

See Also

User Contributed Notes 2 notes

Notice (PHP 5.2.12-pl0-gentoo):
You can parse empty query, you can execute empty query (returns true), but you cannot fetch data from empty query. So, if you provide query as variable, make sure it isn't empty.

Just to write it down. I was trying to do a simple SELECT on a Caché (http://www.intersystems.com/cache/) table through an Oracle dblink, but always received the error "ORA-01002: fetch out of sequence". The solution was using OCI_NO_AUTO_COMMIT on the oci_execute function.