oci_execute
oci_execute
Executes a statement
bool **oci_execute** resource $statement int $mode
Executes a previously returned
from .
statement``oci_parse
After execution, statements like will
have data committed to the database by default. For statements
like , execution performs the logic of the
query. Query results can subsequently be fetched in PHP with
functions like .
INSERT``SELECT``oci_fetch_array
Each parsed statement may be executed multiple times, saving the
cost of re-parsing. This is commonly used
for statements when data is bound
with .
INSERT``oci_bind_by_name
statementA valid OCI statement identifier.
modeAn optional second parameter can be one of the following constants:
Using mode starts or continues a
transaction. Transactions are automatically rolled back when
the connection is closed, or when the script ends. Explicitly
call to commit a transaction,
or to abort it.
`OCI_NO_AUTO_COMMIT``oci_commit``oci_rollback`
When inserting or updating data, using transactions is recommended for relational data consistency and for performance reasons.
If mode is used for any
statement including queries, and
or 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 mode for queries or
PL/SQL. Be careful to ensure the appropriate transactional
consistency for the application when
using with different modes in
the same script.
`OCI_NO_AUTO_COMMIT``oci_commit``oci_rollback``OCI_NO_AUTO_COMMIT``oci_execute`
return.success
Voorbeeld: for queries
<?php
$conn = oci_connect('hr', 'welcome', 'localhost/XE');
$stid = oci_parse($conn, 'SELECT * FROM employees');
oci_execute($stid);
echo "<table border='1'>\n";
while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {
echo "<tr>\n";
foreach ($row as $item) {
echo " <td>" . ($item !== null ? htmlentities($item, ENT_QUOTES) : "nbsp") . "</td>\n";
}
echo "</tr>\n";
}
echo "</table>\n";
?>
Voorbeeld: without specifying a mode example
<?php
// Before running, create the table:
// CREATE TABLE MYTABLE (col1 NUMBER);
$conn = oci_connect('hr', 'welcome', 'localhost/XE');
$stid = oci_parse($conn, 'INSERT INTO mytab (col1) VALUES (123)');
oci_execute($stid); // The row is committed and immediately visible to other users
?>
Voorbeeld: with example
<?php
// Before running, create the table:
// CREATE TABLE MYTABLE (col1 NUMBER);
$conn = oci_connect('hr', 'welcome', 'localhost/XE');
$stid = oci_parse($conn, 'INSERT INTO mytab (col1) VALUES (:bv)');
oci_bind_by_name($stid, ':bv', $i, 10);
for ($i = 1; $i <= 5; ++$i) {
oci_execute($stid, OCI_NO_AUTO_COMMIT);
}
oci_commit($conn); // commits all new values: 1, 2, 3, 4, 5
?>
Voorbeeld: with different commit modes example
<?php
// Before running, create the table:
// CREATE TABLE MYTABLE (col1 NUMBER);
$conn = oci_connect('hr', 'welcome', 'localhost/XE');
$stid = oci_parse($conn, 'INSERT INTO mytab (col1) VALUES (123)');
oci_execute($stid, OCI_NO_AUTO_COMMIT); // data not committed
$stid = oci_parse($conn, 'INSERT INTO mytab (col1) VALUES (456)');
oci_execute($stid); // commits both 123 and 456 values
?>
Voorbeeld: with example
<?php
$conn = oci_connect('hr', 'welcome', 'localhost/XE');
$stid = oci_parse($conn, 'SELECT * FROM locations');
oci_execute($s, OCI_DESCRIBE_ONLY);
for ($i = 1; $i <= oci_num_fields($stid); ++$i) {
echo oci_field_name($stid, $i) . "<br>\n";
}
?>
Opmerking: > Transactions are automatically rolled back when connections are closed, or when the script ends, whichever is soonest. Explicitly call to commit a transaction.
oci_commitAny call to that uses mode explicitly or by default will commit any previous uncommitted transaction.
oci_execute``OCI_COMMIT_ON_SUCCESSAny Oracle DDL statement such as or will automatically commit any uncommitted transaction.
CREATE``DROP
Opmerking: > Because the function generally sends the statement to the database, can identify some statement syntax errors that the lightweight, local function does not.
oci_execute``oci_execute``oci_parse
oci_parse