aci_set_prefetch¶
aci_set_prefetch — 设置预提取行数
说明¶
aci_set_prefetch(resource $statement, int $rows = ?): bool
在成功调用 aci_execute() 之后设定预提取的行数。rows 的默认值为 1。
注意:
在 PHP 5.0.0 之前的版本必须使用 acisetprefetch() 替代本函数。
该函数名仍然可用,为向下兼容作为 aci_set_prefetch() 的别名。不过其已被废弃,不推荐使用。
成功时返回 true, 或者在失败时返回 false。
参见 aci8_default_prefetch INI 选项。
返回值¶
成功时返回 true, 或者在失败时返回 false。
范例¶
示例 #1更改查询的默认预取值
<?php
$conn = aci_connect('sysdba', 'szoscar55', 'localhost:2003/OSRDB');
$stid = aci_parse($conn, 'SELECT * FROM myverybigtable');
aci_set_prefetch($stid, 300); // Set before calling aci_execute()
aci_execute($stid);
echo "<table border='1'>\n";
while ($row = aci_fetch_array($stid, aci_ASSOC+aci_RETURN_NULLS)) {
echo "<tr>\n";
foreach ($row as $item) {
echo " <td>".($item !== null ? htmlentities($item, ENT_QUOTES) : " ")."</td>\n";
}
echo "</tr>\n";
}
echo "</table>\n";
aci_free_statement($stid);
aci_close($conn);
?>
示例 #2更改REF CURSOR提取的默认预取
<?php
/*
Create the PL/SQL stored procedure as:
CREATE OR REPLACE PROCEDURE myproc(p1 OUT SYS_REFCURSOR) AS
BEGIN
OPEN p1 FOR SELECT * FROM all_objects WHERE ROWNUM < 5000;
END;
*/
$conn = aci_connect('sysdba', 'szoscar55', 'localhost:2003/OSRDB');
$stid = aci_parse($conn, 'BEGIN myproc(:rc); END;');
$refcur = aci_new_cursor($conn);
aci_bind_by_name($stid, ':rc', $refcur, -1, aci_B_CURSOR);
aci_execute($stid);
// Change the prefetch before executing the cursor.
// REF CURSOR prefetching works when PHP is linked with Oracle 11gR2 Client libraries
aci_set_prefetch($refcur, 200);
aci_execute($refcur);
echo "<table border='1'>\n";
while ($row = aci_fetch_array($refcur, aci_ASSOC+aci_RETURN_NULLS)) {
echo "<tr>\n";
foreach ($row as $item) {
echo " <td>".($item !== null ? htmlentities($item, ENT_QUOTES) : " ")."</td>\n";
}
echo "</tr>\n";
}
echo "</table>\n";
aci_free_statement($refcur);
aci_free_statement($stid);
aci_close($conn);
?>
如果PHP ACI8从REF CURSOR中提取,然后将REF CURSOR传回第二个PL/SQL过程进行进一步处理,则将REF CURSOR预取计数设置为0,以避免结果集中的行“丢失”。 预取值是在对数据库的每个ACI8内部请求中提取的额外行数,因此将其设置为0意味着每次只提取一行。
示例 #3将REF CURSOR传回Oracle时设置预取值
<?php
$conn = aci_connect('sysdba', 'szoscar55', 'localhost:2003/OSRDB');
// get the REF CURSOR
$stid = aci_parse($conn, 'BEGIN myproc(:rc_out); END;');
$refcur = aci_new_cursor($conn);
aci_bind_by_name($stid, ':rc_out', $refcur, -1, aci_B_CURSOR);
aci_execute($stid);
// Display two rows, but don't prefetch any extra rows otherwise
// those extra rows would not be passed back to myproc_use_rc().
// A prefetch value of 0 is allowed in PHP 5.3.2 and PECL OCI8 1.4
aci_set_prefetch($refcur, 0);
aci_execute($refcur);
$row = aci_fetch_array($refcur);
var_dump($row);
$row = aci_fetch_array($refcur);
var_dump($row);
// pass the REF CURSOR to myproc_use_rc() to do more data processing
// with the result set
$stid = aci_parse($conn, 'begin myproc_use_rc(:rc_in); end;');
aci_bind_by_name($stid, ':rc_in', $refcur, -1, aci_B_CURSOR);
aci_execute($stid);
?>
参考¶
aci8.default_prefetch ini option