aci_new_cursor¶
aci_new_cursor — 分配并返回一个新的游标(语句句柄)
说明¶
aci_new_cursor(resource $connection): resource
aci_new_cursor() 在指定的连接上分配一个新的语句句柄。
示例 #1 在 数据库 的存储过程中使用 REF CURSOR
<?php
// suppose your stored procedure info.output returns a ref cursor in :data
$conn = aci_connect('sysdba', 'szoscar55', 'localhost:2003/OSRDB');
$curs = aci_new_cursor($conn);
$stmt = aci_parse($conn, "begin info.output(:data); end;");
aci_bind_by_name($stmt, "data", $curs, -1, aci_B_CURSOR);
aci_execute($stmt);
aci_execute($curs);
while ($data = aci_fetch_row($curs)) {
var_dump($data);
}
aci_free_statement($stmt);
aci_free_statement($curs);
aci_close($conn);
?>
示例 #2 在 数据库 的 select 语句中使用 REF CURSOR
<?php
echo "<html><body>";
$conn = aci_connect('sysdba', 'szoscar55', 'localhost:2003/OSRDB');
$count_cursor = "CURSOR(select count(empno) num_emps from emp " .
"where emp.deptno = dept.deptno) as EMPCNT from dept";
$stmt = aci_parse($conn, "select deptno,dname,$count_cursor");
aci_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 = aci_fetch_assoc($stmt)) {
echo "<tr>";
$dname = $data["DNAME"];
$deptno = $data["DEPTNO"];
echo "<td>$dname</td>";
echo "<td>$deptno</td>";
aci_execute($data["EMPCNT"]);
while ($subdata = aci_fetch_assoc($data["EMPCNT"])) {
$num_emps = $subdata["NUM_EMPS"];
echo "<td>$num_emps</td>";
}
echo "</tr>";
}
echo "</table>";
echo "</body></html>";
aci_free_statement($stmt);
aci_close($conn);
?>
aci_new_cursor() 如果出错返回 false。
注意:
在 PHP 5.0.0 之前的版本必须使用 acinewcursor() 替代本函数。该函数名仍然可用,为向下兼容作为 aci_new_cursor() 的别名。不过其已被废弃,不推荐使用。