PHP Manual
Prev |  | Next

# OCINewCursor

OCINewCursor -- return a new cursor (Statement-Handle) - use this to bind ref-cursors!

## Description

`int OCINewCursor`(int conn);

OCINewCursor() allocates a new statement handle on the specified connection.

Example 1. Using a REF CURSOR from a stored procedure
      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 ?>

Example 2. Using a REF CURSOR in a select statement
      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 ?>

Prev | Home | Next
OCIStatementType | Up | OCIFreeStatement