&reftitle.examples;
These examples connect as the HR user, which is
the sample "Human Resources" schema supplied with the
Oracle database. The account may need to be unlocked and the
password reset before you can use it.
The examples connect to the XE database on your
machine. Change the connect string to your database before running
the examples.
Basic query
This shows querying and displaying results. Statements in OCI8 use
a prepare-execute-fetch sequence of steps.
\n";
while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {
print "
\n";
}
print "\n";
oci_free_statement($stid);
oci_close($conn);
?>
]]>
Inserting with bind variables
Bind variables improve performance by allowing reuse of execution
contexts and caches. Bind variables improve security by preventing
some kinds of SQL Injection problems.
]]>
Inserting data into a CLOB column
For large data use binary long object (BLOB) or character long
object (CLOB) types. This example uses CLOB.
save("A very long string");
oci_commit($conn);
// Fetching CLOB data
$query = 'SELECT myclob FROM mytable WHERE mykey = :mykey';
$stid = oci_parse ($conn, $query);
oci_bind_by_name($stid, ":mykey", $mykey, 5);
oci_execute($stid);
print '
';
?>
]]>
Using a PL/SQL stored function
You must bind a variable for the return value and optionally for
any PL/SQL function arguments.
]]>
Using a PL/SQL stored procedure
With stored procedures, you should bind variables for any arguments.
]]>
Calling a PL/SQL function that returns a REF CURSOR
Each returned value from the query is a REF
CURSOR that can be fetched from.
\n";
while (($row = oci_fetch_array($stid, OCI_ASSOC))) {
echo "
\n";
$rc = $row['MFRC'];
oci_execute($rc); // returned column value from the query is a ref cursor
while (($rc_row = oci_fetch_array($rc, OCI_ASSOC))) {
echo "