php-doc-en/reference/oci8/functions/ocinewcursor.xml
2003-02-11 03:06:15 +00:00

113 lines
2.8 KiB
XML

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.3 $ -->
<!-- splitted from ./en/functions/oci8.xml, last change in rev 1.2 -->
<refentry id="function.ocinewcursor">
<refnamediv>
<refname>ocinewcursor</refname>
<refpurpose>
Return a new cursor (Statement-Handle)
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>resource</type><methodname>ocinewcursor</methodname>
<methodparam><type>resource</type><parameter>conn</parameter></methodparam>
</methodsynopsis>
<para>
<function>ocinewcursor</function> allocates a new statement handle
on the specified connection.
</para>
<para>
<example>
<title>Using a REF CURSOR from a stored procedure</title>
<programlisting>
<![CDATA[
<?php
// suppose your stored procedure info.output returns a ref cursor in :data
$conn = OCILogon("scott","tiger");
$curs = OCINewCursor($conn);
$stmt = OCIParse($conn,"begin info.output(:data); end;");
ocibindbyname($stmt,"data",&$curs,-1,OCI_B_CURSOR);
ociexecute($stmt);
ociexecute($curs);
while (OCIFetchInto($curs,&$data)) {
var_dump($data);
}
OCIFreeStatement($stmt);
OCIFreeCursor($curs);
OCILogoff($conn);
?>
]]>
</programlisting>
</example>
</para>
<para>
<example>
<title>Using a REF CURSOR in a select statement</title>
<programlisting>
<![CDATA[
<?php
print "<HTML><BODY>";
$conn = OCILogon("scott","tiger");
$count_cursor = "CURSOR(select count(empno) num_emps from emp " .
"where emp.deptno = dept.deptno) as EMPCNT from dept";
$stmt = OCIParse($conn,"select deptno,dname,$count_cursor");
ociexecute($stmt);
print "<TABLE BORDER=\"1\">";
print "<TR>";
print "<TH>DEPT NAME</TH>";
print "<TH>DEPT #</TH>";
print "<TH># EMPLOYEES</TH>";
print "</TR>";
while (OCIFetchInto($stmt,&$data,OCI_ASSOC)) {
print "<TR>";
$dname = $data["DNAME"];
$deptno = $data["DEPTNO"];
print "<TD>$dname</TD>";
print "<TD>$deptno</TD>";
ociexecute($data["EMPCNT"]);
while (OCIFetchInto($data["EMPCNT"],&$subdata,OCI_ASSOC)) {
$num_emps = $subdata["NUM_EMPS"];
print "<TD>$num_emps</TD>";
}
print "</TR>";
}
print "</TABLE>";
print "</BODY></HTML>";
OCIFreeStatement($stmt);
OCILogoff($conn);
?>
]]>
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<!-- 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
-->