oci_new_cursor

(PHP 5, PECL OCI8 >= 1.1.0)

oci_new_cursorAlloue un nouveau curseur Oracle

Description

resource oci_new_cursor ( resource $connection )

Alloue un nouveau curseur Oracle sur la connexion spécifiée.

Liste de paramètres

connection

Un identifiant de connexion Oracle, retourné par la fonction oci_connect() ou la fonction oci_pconnect().

Valeurs de retour

Retourne un nouveau gestionnaire de connexion, ou FALSE si une erreur survient.

Exemples

Exemple #1 Utiliser un REF CURSOR issu d'une procédure enregistrée

  1. <?php
  2. // supposons que votre procédure stockée info.output retourne un curseur de référence dans :data
  3.  
  4. $conn = oci_connect("scott", "tiger");
  5. $curs = oci_new_cursor($conn);
  6. $stmt = oci_parse($conn, "begin info.output(:data); end;");
  7.  
  8. oci_bind_by_name($stmt, "data", $curs, -1, OCI_B_CURSOR);
  9. oci_execute($stmt);
  10. oci_execute($curs);
  11.  
  12. while ($data = oci_fetch_row($curs)) {
  13. var_dump($data);
  14. }
  15.  
  16. oci_free_statement($stmt);
  17. oci_free_statement($curs);
  18. oci_close($conn);
  19. ?>

Exemple #2 Utiliser un REF CURSOR issu d'une commande SELECT

  1. <?php
  2. echo "<html><body>";
  3. $conn = oci_connect("scott", "tiger");
  4. $count_cursor = "CURSOR(select count(empno) num_emps from emp " .
  5. "where emp.deptno = dept.deptno) as EMPCNT from dept";
  6. $stmt = oci_parse($conn, "select deptno,dname,$count_cursor");
  7.  
  8. oci_execute($stmt);
  9. echo "<table border=\"1\">";
  10. echo "<tr>";
  11. echo "<th>DEPT NAME</th>";
  12. echo "<th>DEPT #</th>";
  13. echo "<th># EMPLOYEES</th>";
  14. echo "</tr>";
  15.  
  16. while ($data = oci_fetch_assoc($stmt)) {
  17. echo "<tr>";
  18. $dname = $data["DNAME"];
  19. $deptno = $data["DEPTNO"];
  20. echo "<td>$dname</td>";
  21. echo "<td>$deptno</td>";
  22. oci_execute($data["EMPCNT"]);
  23. while ($subdata = oci_fetch_assoc($data["EMPCNT"])) {
  24. $num_emps = $subdata["NUM_EMPS"];
  25. echo "<td>$num_emps</td>";
  26. }
  27. echo "</tr>";
  28. }
  29. echo "</table>";
  30. echo "</body></html>";
  31. oci_free_statement($stmt);
  32. oci_close($conn);
  33. ?>

Notes

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.

LoadingChargement en cours