downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

oci_fetch_all> <oci_error
Last updated: Fri, 13 Nov 2009

view this page in

oci_execute

(PHP 5, PECL OCI8 >= 1.1.0)

oci_executeExecutes a statement

Descrição

bool oci_execute ( resource $statement [, int $mode = OCI_COMMIT_ON_SUCCESS ] )

Executes a statement previously returned from oci_parse().

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().

Parâmetros

statement

A valid OCI statement identifier.

mode

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

  • OCI_COMMIT_ON_SUCCESS - Automatically commit changes when the statement has succeeded. This is the default.
  • OCI_NO_AUTO_COMMIT - Do not automatically commit changes. Prior to PHP 5.3.2 and for PECL oci8 < 1.4 use OCI_DEFAULT which is an alias for OCI_NO_AUTO_COMMIT.
  • OCI_DESCRIBE_ONLY - Make query meta data available to functions like oci_field_name() but do not create a result set. Any subsequent fetch call such as oci_fetch_array() will fail.

When using OCI_NO_AUTO_COMMIT mode, you're creating 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.

Using transactions is recommended for relational data consistency and for performance reasons.

Valor Retornado

Retorna TRUE em caso de sucesso ou FALSE em falhas.

Exemplos

Exemplo #1 oci_execute() for queries

<?php

$connection 
oci_connect("hr""welcome""localhost/XE");

$statement oci_parse($connection"SELECT * FROM employees");
oci_execute($statement);

echo 
"<table border='1'>\n";
while (
$row oci_fetch_array($statementOCI_ASSOC+OCI_RETURN_NULLS)) {
    echo 
"<tr>\n";
    foreach (
$row as $item) {
        echo 
"    <td>".($item!==null?htmlentities($itemENT_QUOTES):"&nbsp;")."</td>\n";
    }
    echo 
"</tr>\n";
}
echo 
"</table>\n";

?>

Exemplo #2 oci_execute() without specifying a mode example

<?php

$connection 
oci_connect("hr""welcome""localhost/XE");

$statement oci_parse($connection"INSERT INTO mytab (col1) VALUES (123)");

oci_execute($statement); // The row is committed and immediately visible to other users

?>

Exemplo #3 oci_execute() with OCI_NO_AUTO_COMMIT example

<?php

$connection 
oci_connect("hr""welcome""localhost/XE");

$statement oci_parse($connection"INSERT INTO mytab (col1) VALUES (:bv)");
oci_bind_by_name($statement":bv"$i10);
for (
$i 1$i <= 5; ++$i) {
    
oci_execute($statementOCI_NO_AUTO_COMMIT);  // use OCI_DEFAULT for PHP <= 5.3.1
}
oci_commit($connection);  // commits all new values: 1, 2, 3, 4, 5

?>

Exemplo #4 oci_execute() with different commit modes example

<?php

$connection 
oci_connect("hr""welcome""localhost/XE");

$statement oci_parse($connection"INSERT INTO mytab (col1) VALUES (123)");
oci_execute($statementOCI_NO_AUTO_COMMIT);  // data not committed

$statement oci_parse($connection"INSERT INTO mytab (col1) VALUES (456)");
oci_execute($statement);  // commits both 123 and 456 values

?>

Exemplo #5 oci_execute() with OCI_DESCRIBE_ONLY example

<?php

$connection 
oci_connect("hr""welcome""localhost/XE");

$statement oci_parse($connection"SELECT * FROM mytab");
oci_execute($sOCI_DESCRIBE_ONLY);
for (
$i 1$i <= oci_num_fields($statement); ++$i) {
    echo 
oci_field_name($statement$i) . "<br>\n";
}

?>

Notas

Nota: 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.

Nota: Because the oci_execute() function generally sends the statement to the database, oci_execute() can identify some statement syntax errors that the lightweight, local oci_parse() function does not.

Nota: In PHP versions before 5.0.0 you must use ociexecute() instead. The old function name can still be used in current versions, however it is deprecated and not recommended.

Veja Também

  • oci_parse() - Prepares an Oracle statement for execution



add a note add a note User Contributed Notes
oci_execute
There are no user contributed notes for this page.

oci_fetch_all> <oci_error
Last updated: Fri, 13 Nov 2009
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites