PHP Doku:: Allocates and returns a new cursor (statement handle) - function.oci-new-cursor.html

Verlauf / Chronik / History: (1) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzDatenbankerweiterungenAnbieterspezifische DatenbankerweiterungenOracle OCI8OCI8 Funktionenoci_new_cursor

Ein Service von Reinhard Neidl - Webprogrammierung.

OCI8 Funktionen

<<oci_new_connect

oci_new_descriptor>>

oci_new_cursor

(PHP 5, PECL OCI8 >= 1.1.0)

oci_new_cursorAllocates and returns a new cursor (statement handle)

Beschreibung

resource oci_new_cursor ( resource $connection )

Allocates a new statement handle on the specified connection.

Parameter-Liste

connection

An Oracle connection identifier, returned by oci_connect() or oci_pconnect().

Rückgabewerte

Returns a new statement handle, or FALSE on error.

Beispiele

Beispiel #1 Using REF CURSOR in an Oracle's stored procedure

<?php
// suppose your stored procedure info.output returns a ref cursor in :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, -1OCI_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);
?>

Beispiel #2 Using REF CURSOR in an Oracle's select statement

<?php
echo "<html><body>";
$conn oci_connect("scott""tiger");
$count_cursor "CURSOR(select count(empno) num_emps from emp " .
                
"where emp.deptno = dept.deptno) as EMPCNT from dept";
$stmt oci_parse($conn"select deptno,dname,$count_cursor");

oci_execute($stmt);
echo 
"<table border=\"1\">";
echo 
"<tr>";
echo 
"<th>DEPT NAME</th>";
echo 
"<th>DEPT #</th>";
echo 
"<th># EMPLOYEES</th>";
echo 
"</tr>";

while (
$data oci_fetch_assoc($stmt)) {
    echo 
"<tr>";
    
$dname  $data["DNAME"];
    
$deptno $data["DEPTNO"];
    echo 
"<td>$dname</td>";
    echo 
"<td>$deptno</td>";
    
oci_execute($data["EMPCNT"]);
    while (
$subdata oci_fetch_assoc($data["EMPCNT"])) {
        
$num_emps $subdata["NUM_EMPS"];
        echo  
"<td>$num_emps</td>";
    }
    echo 
"</tr>";
}
echo 
"</table>";
echo 
"</body></html>";
oci_free_statement($stmt);
oci_close($conn);
?>

Anmerkungen

Hinweis:

In PHP versions before 5.0.0 you must use ocinewcursor() instead. This name still can be used, it was left as alias of oci_new_cursor() for downwards compatability. This, however, is deprecated and not recommended.


2 BenutzerBeiträge:
- Beiträge aktualisieren...
sixd at php dot net
28.01.2010 7:41
Oracle 11.2 introduced support for REF CURSOR prefetching
sixd at php dot net
5.11.2008 21:13
Because OCI8 uses "prefetching" to greatly improve returning query results, but Oracle doesn't support prefetching for REF CURSORs, application performance using REF CURSORs can be greatly improved by writing a PL/SQL function that pulls data from the REF CURSOR and PIPEs the output. The new function can be queried in a SELECT as if it were a table.  See http://blogs.oracle.com/opal/2008/11/
converting_ref_cursor_to_pipe.html



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)