oci_new_cursor oci_new_cursor (PHP 5)
oci_new_cursor -- Alloue un nouveau curseur Oracle
Description resource
oci_new_cursor ( resource connection )
ocinewcursor() alloue un nouveau pointeur
de commande, pour la connexion connection .
Exemple 1.
Utiliser un REF CURSOR issu d'une procédure enregistrée
<?php // supposons que votre procédure stockée info.output retourne un curseur de référence dans :data $conn = oci_connect ( "scott" , "tiger" ); $curs = oci_new_cursor ( $conn ); $stmt = oci_parse ( $conn , "begin info.output(:data); end;" ); oci_bind_by_name ( $stmt , "data" , $curs , - 1 , OCI_B_CURSOR ); oci_execute ( $stmt ); oci_execute ( $curs ); while ( $data = oci_fetch_row ( $curs )) { var_dump ( $data ); } oci_free_statement ( $stmt ); oci_free_statement ( $curs ); oci_close ( $conn ); ?>
Exemple 2. Utiliser un REF CURSOR issu d'une commande SELECT
<?php echo '<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 ); echo '<table border="1">' ; echo '<tr>' ; echo '<th>DEPT NAME</th>' ; echo '<th>DEPT #</th>' ; echo '<th># EMPLOYEES</th>' ; echo '</tr>' ; while ( OCIFetchInto ( $stmt ,& $data , OCI_ASSOC )) { echo '<tr>' ; $dname = $data [ "DNAME" ]; $deptno = $data [ "DEPTNO" ]; echo "<td>$dname</td>" ; echo "<td>$deptno</td>" ; ociexecute ( $data [ "EMPCNT" ]); while ( OCIFetchInto ( $data [ "EMPCNT" ],& $subdata , OCI_ASSOC )) { $num_emps = $subdata [ "NUM_EMPS" ]; echo "<td>$num_emps</td>" ; } echo '</tr>' ; } echo '</table>' ; echo '</body></html>' ; OCIFreeStatement ( $stmt ); OCILogoff ( $conn ); ?>
oci_new_cursor() retourne FALSE en cas d'erreur.
Note :
Dans les versions de PHP antérieures à la version 5.0.0,
vous devez utiliser la fonction ocinewcursor() .
Cet ancien nom est toujours utilisable : un alias a été fait vers
la fonction oci_new_collection() , pour assurer
la compatibilité ascendante. Toutefois, il est recommandé de ne
plus l'utiliser.
Manuel PHP pour PHP-Nuke © www.stefvar.com