<HTML ><HEAD ><TITLE >OCINewCursor</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.44"><LINK REL="HOME" TITLE="PHP Manual" HREF="manual.html"><LINK REL="UP" TITLE="Oracle 8 functions" HREF="ref.oci8.html"><LINK REL="PREVIOUS" TITLE="OCIStatementType" HREF="function.ocistatementtype.html"><LINK REL="NEXT" TITLE="OCIFreeStatement" HREF="function.ocifreestatement.html"></HEAD ><BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PHP Manual</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.ocistatementtype.html" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.ocifreestatement.html" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.ocinewcursor" >OCINewCursor</A ></H1 ><DIV CLASS="refnamediv" ><A NAME="AEN20974" ></A >OCINewCursor -- return a new cursor (Statement-Handle) - use this to bind ref-cursors!</DIV ><DIV CLASS="refsect1" ><A NAME="AEN20977" ></A ><H2 >Description</H2 ><DIV CLASS="funcsynopsis" ><P ></P ><CODE CLASS="FUNCDEF" >int OCINewCursor</CODE >(int conn);<P ></P ></DIV ><P > <B CLASS="function" >OCINewCursor()</B > allocates a new statement handle on the specified connection. </P ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><P ><B >Example 1. Using a REF CURSOR from a stored procedure</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="programlisting" > 1 2 <?php 3 // suppose your stored procedure info.output returns a ref cursor in :data 4 5 $conn = OCILogon("scott","tiger"); 6 $curs = OCINewCursor($conn); 7 $stmt = OCIParse($conn,"begin info.output(:data); end;"); 8 9 ocibindbyname($stmt,"data",&$curs,-1,OCI_B_CURSOR); 10 ociexecute($stmt); 11 ociexecute($curs); 12 13 while (OCIFetchInto($curs,&$data)) { 14 var_dump($data); 15 } 16 17 OCIFreeCursor($stmt); 18 OCIFreeStatement($curs); 19 OCILogoff($conn); 20 ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ></P ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><P ><B >Example 2. Using a REF CURSOR in a select statement</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="programlisting" > 1 2 <?php 3 print "<HTML><BODY>"; 4 $conn = OCILogon("scott","tiger"); 5 $count_cursor = "CURSOR(select count(empno) num_emps from emp " . 6 "where emp.deptno = dept.deptno) as EMPCNT from dept"; 7 $stmt = OCIParse($conn,"select deptno,dname,$count_cursor"); 8 9 ociexecute($stmt); 10 print "<TABLE BORDER=\"1\">"; 11 print "<TR>"; 12 print "<TH>DEPT NAME</TH>"; 13 print "<TH>DEPT #</TH>"; 14 print "<TH># EMPLOYEES</TH>"; 15 print "</TR>"; 16 17 while (OCIFetchInto($stmt,&$data,OCI_ASSOC)) { 18 print "<TR>"; 19 $dname = $data["DNAME"]; 20 $deptno = $data["DEPTNO"]; 21 print "<TD>$dname</TD>"; 22 print "<TD>$deptno</TD>"; 23 ociexecute($data[ "EMPCNT" ]); 24 while (OCIFetchInto($data[ "EMPCNT" ],&$subdata,OCI_ASSOC)) { 25 $num_emps = $subdata["NUM_EMPS"]; 26 print "<TD>$num_emps</TD>"; 27 } 28 print "</TR>"; 29 } 30 print "</TABLE>"; 31 print "</BODY></HTML>"; 32 OCIFreeStatement($stmt); 33 OCILogoff($conn); 34 ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ></P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.ocistatementtype.html" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="manual.html" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.ocifreestatement.html" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >OCIStatementType</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.oci8.html" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >OCIFreeStatement</TD ></TR ></TABLE ></DIV ></BODY ></HTML >