ocinewcursor
(PHP 3 >= 3.0.8, PHP 4, PHP 5)
ocinewcursor --
新規カーソル(命令ハンドル)を返す
説明
resource
ocinewcursor ( resource conn )
ocinewcursor() は、新規の命令ハンドル
を指定した接続に確保します。
例 1. Oracle
におけるストアドプロシージャからの参照カーソルの使用例
<?php // ストアドプロシージャ info.output が :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); ?>
|
|
例 2. Oracle
の 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); ?>
|
|
注意:
この関数は PHP >= 5.0.0 以降 oci_new_cursor()
に改名されました。
下位互換性のため、 ocinewcursor()
も使用することができますが、推奨されません。