ocinewcursor

(PHP 3>= 3.0.8, PHP 4 )

ocinewcursor --  Retourne un nouveau pointeur à utiliser pour lier les pointeurs de références

Description

resource ocinewcursor ( resource conn)

ocinewcursor() alloue un nouveau pointeur de commande, pour la connexion conn.

Exemple 1. Utiliser un REF CURSOR issue d'une procédure enregistrée

<?php   
// supposons que votre proc&eacute;dure stock&eacute;e info.output retourne un curseur de r&eacute;f&eacute;rence dans :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);
?>

Exemple 2. Utiliser un REF CURSOR issue d'une commande SELECT

<?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);
?>