mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-29 23:38:56 +00:00

- Split reference.xml into book.xml, setup.xml, connection.xml, datatypes.xml, examples.xml - Moved from reference.xml: - To book.xml: The intro text (partintro), and link to various pages - To setup.xml: requirements, configuration, and added installation and resources - To connection.xml: The connection handling section to a new chapter - To datatypes.xml: The data type section to a new chapter - To examples.xml: The examples section to a new chapter - Changed the constants section to be an <appendix> - Changed the intro ID from <extname>.intro to intro.<extname> git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@248868 c90b9560-bf6c-de11-be94-00142212c4b1
184 lines
4.1 KiB
XML
184 lines
4.1 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision: 1.2 $ -->
|
|
<chapter xml:id="oci8.examples" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
&reftitle.examples;
|
|
<section xml:id="oci8.examples-basic">
|
|
<para>
|
|
<example>
|
|
<title>Basic query</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
|
|
$conn = oci_connect('hr', 'hr', 'orcl');
|
|
if (!$conn) {
|
|
$e = oci_error();
|
|
print htmlentities($e['message']);
|
|
exit;
|
|
}
|
|
|
|
$query = 'SELECT * FROM DEPARTMENTS';
|
|
|
|
$stid = oci_parse($conn, $query);
|
|
if (!$stid) {
|
|
$e = oci_error($conn);
|
|
print htmlentities($e['message']);
|
|
exit;
|
|
}
|
|
|
|
$r = oci_execute($stid, OCI_DEFAULT);
|
|
if (!$r) {
|
|
$e = oci_error($stid);
|
|
echo htmlentities($e['message']);
|
|
exit;
|
|
}
|
|
|
|
print '<table border="1">';
|
|
while ($row = oci_fetch_array($stid, OCI_RETURN_NULLS)) {
|
|
print '<tr>';
|
|
foreach ($row as $item) {
|
|
print '<td>'.($item?htmlentities($item):' ').'</td>';
|
|
}
|
|
print '</tr>';
|
|
}
|
|
print '</table>';
|
|
|
|
oci_close($conn);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>Insert with bind variables</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
|
|
// Before running, create the table:
|
|
// CREATE TABLE MYTABLE (mid NUMBER, myd VARCHAR2(20));
|
|
|
|
$conn = oci_connect('scott', 'tiger', 'orcl');
|
|
|
|
$query = 'INSERT INTO MYTABLE VALUES(:myid, :mydata)';
|
|
|
|
$stid = oci_parse($conn, $query);
|
|
|
|
$id = 60;
|
|
$data = 'Some data';
|
|
|
|
oci_bind_by_name($stid, ':myid', $id);
|
|
oci_bind_by_name($stid, ':mydata', $data);
|
|
|
|
$r = oci_execute($stid);
|
|
|
|
if ($r)
|
|
print "One row inserted";
|
|
|
|
oci_close($conn);
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
|
|
|
|
<para>
|
|
<example>
|
|
<title>Inserting data into a CLOB column</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
|
|
// Before running, create the table:
|
|
// CREATE TABLE MYTABLE (mykey NUMBER, myclob CLOB);
|
|
|
|
$conn = oci_connect('scott', 'tiger', 'orcl');
|
|
|
|
$mykey = 12343; // arbitrary key for this example;
|
|
|
|
$sql = "INSERT INTO mytable (mykey, myclob)
|
|
VALUES (:mykey, EMPTY_CLOB())
|
|
RETURNING myclob INTO :myclob";
|
|
|
|
$stid = oci_parse($conn, $sql);
|
|
$clob = oci_new_descriptor($conn, OCI_D_LOB);
|
|
oci_bind_by_name($stid, ":mykey", $mykey, 5);
|
|
oci_bind_by_name($stid, ":myclob", $clob, -1, OCI_B_CLOB);
|
|
oci_execute($stid, OCI_DEFAULT);
|
|
$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, OCI_DEFAULT);
|
|
|
|
print '<table border="1">';
|
|
while ($row = oci_fetch_array($stid, OCI_ASSOC)) {
|
|
$result = $row['MYCLOB']->load();
|
|
print '<tr><td>'.$result.'</td></tr>';
|
|
}
|
|
print '</table>';
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
You can easily access stored procedures in the same way as you
|
|
would from the command line.
|
|
<example>
|
|
<title>Using Stored Procedures</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
// by webmaster at remoterealty dot com
|
|
$sth = oci_parse($dbh, "begin sp_newaddress( :address_id, '$firstname',
|
|
'$lastname', '$company', '$address1', '$address2', '$city', '$state',
|
|
'$postalcode', '$country', :error_code );end;");
|
|
|
|
// This calls stored procedure sp_newaddress, with :address_id being an
|
|
// in/out variable and :error_code being an out variable.
|
|
// Then you do the binding:
|
|
|
|
oci_bind_by_name($sth, ":address_id", $addr_id, 10);
|
|
oci_bind_by_name($sth, ":error_code", $errorcode, 10);
|
|
oci_execute($sth);
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
</section>
|
|
</chapter>
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"../../../manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|
|
|