aci_fetch_all¶
aci_fetch_all — 获取结果数据的所有行到一个数组
说明¶
aci_fetch_all(
resource $statement,
array &$output,
int $skip = ?,
int $maxrows = ?,
int $flags = ?
): int
aci_fetch_all() 从一个结果中获取所有的行到一个用户定义的数组。aci_fetch_all() 返回获取的行数,出错则返回 false。 skip 是从结果中获取数据时,最开始忽略的行数(默认值是 0,即从第一行开始)。maxrows 是要读取的行数,从第 skip 行开始(默认值是 -1,即所有行)。
flags 参数可以是下列值的任意组合:
- aci_FETCHSTATEMENT_BY_ROW
- aci_FETCHSTATEMENT_BY_COLUMN(默认值)
- aci_NUM
- aci_ASSOC
示例 #1 aci_fetch_all() 例子
<?php
/* aci_fetch_all example mbritton at verinet dot com (990624) */
$conn = aci_connect('sysdba', 'szoscar55', 'localhost:2003/OSRDB');
$stmt = aci_parse($conn, "select * from emp");
aci_execute($stmt);
$nrows = aci_fetch_all($stmt, $results);
if ($nrows > 0) {
echo "<table border=\"1\">\n";
echo "<tr>\n";
foreach ($results as $key => $val) {
echo "<th>$key</th>\n";
}
echo "</tr>\n";
for ($i = 0; $i < $nrows; $i++) {
echo "<tr>\n";
foreach ($results as $data) {
echo "<td>$data[$i]</td>\n";
}
echo "</tr>\n";
}
echo "</table>\n";
} else {
echo "No data found<br />\n";
}
echo "$nrows Records Selected<br />\n";
aci_free_statement($stmt);
aci_close($conn);
?>
aci_fetch_all() 如果出错则返回 false。
注意:
在 PHP 5.0.0 之前的版本必须使用 acifetchstatement() 替代本函数。该函数名仍然可用,为向下兼容作为 aci_fetch_all() 的别名。不过其已被废弃,不推荐使用。
参数¶
有效的ACI8标识符 由 aci_parse()创建,被 aci_execute()或 REF CURSOR语句标识执行。
包含返回行的变量。 LOB列作为字符串返回,数据库支持转换。 有关如何获取数据和类型的更多信息,请参见aci_fetch_array().
获取结果时要丢弃的初始行数。默认值为0,因此将返回第一行。
要返回的行数。默认值为-1,表示从跳过+1开始返回所有行。
参数标志指示数组结构以及是否应使用关联数组。
| Constant | Description |
|---|---|
| aci_FETCHSTATEMENT_BY_ROW | 外部数组将包含每个查询行一个子数组。 |
| aci_FETCHSTATEMENT_BY_COLUMN | 外部数组将包含每个查询列一个子数组。这是默认设置。 |
数组可以按列标题或数字索引。
| Constant | Description |
|---|---|
| aci_NUM | 数值索引用于每个列的数组。 |
| aci_ASSOC | 关联索引用于每个列的数组。这是默认设置。 |
使用加法运算符“+”选择数组结构和索引模式的组合。
数据库的默认、不区分大小写的列名将具有大写数组键。区分大小写的列名将具有使用精确列大小写的数组键。对输出使用var_dump()来验证每个查询要使用的适当大小写。
具有多个同名列的查询应使用列别名。否则,关联数组中将只显示其中一列。
返回值¶
返回输出中的行数,可以是0或更多,或者在失败时返回 错误。
范例¶
示例 #2 aci_fetch_all() example
<?php
$conn = aci_connect('sysdba', 'szoscar55', 'localhost:2003/OSRDB');
if (!$conn) {
$e = aci_error();
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}
$stid = aci_parse($conn, 'SELECT POSTAL_CODE, CITY FROM locations WHERE ROWNUM < 3');
aci_execute($stid);
$nrows = aci_fetch_all($stid, $res);
echo "$nrows rows fetched<br>\n";
var_dump($res);
// var_dump output is:
// 2 rows fetched
// array(2) {
// ["POSTAL_CODE"]=>
// array(2) {
// [0]=>
// string(6) "00989x"
// [1]=>
// string(6) "10934x"
// }
// ["CITY"]=>
// array(2) {
// [0]=>
// string(4) "Roma"
// [1]=>
// string(6) "Venice"
// }
// }
// Pretty-print the results
echo "<table border='1'>\n";
foreach ($res as $col) {
echo "<tr>\n";
foreach ($col 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);
?>
示例 #3 aci_fetch_all() example with aci_FETCHSTATEMENT_BY_ROW
<?php
$conn = aci_connect('sysdba', 'szoscar55', 'localhost:2003/OSRDB');
if (!$conn) {
$e = aci_error();
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}
$stid = aci_parse($conn, 'SELECT POSTAL_CODE, CITY FROM locations WHERE ROWNUM < 3');
aci_execute($stid);
$nrows = aci_fetch_all($stid, $res, null, null, aci_FETCHSTATEMENT_BY_ROW);
echo "$nrows rows fetched<br>\n";
var_dump($res);
// Output is:
// 2 rows fetched
// array(2) {
// [0]=>
// array(2) {
// ["POSTAL_CODE"]=>
// string(6) "00989x"
// ["CITY"]=>
// string(4) "Roma"
// }
// [1]=>
// array(2) {
// ["POSTAL_CODE"]=>
// string(6) "10934x"
// ["CITY"]=>
// string(6) "Venice"
// }
// }
aci_free_statement($stid);
aci_close($conn);
?>
示例 #4 aci_fetch_all() with aci_NUM
<?php
$conn = aci_connect('sysdba', 'szoscar55', 'localhost:2003/OSRDB');
if (!$conn) {
$e = aci_error();
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}
$stid = aci_parse($conn, 'SELECT POSTAL_CODE, CITY FROM locations WHERE ROWNUM < 3');
aci_execute($stid);
$nrows = aci_fetch_all($stid, $res, null, null, aci_FETCHSTATEMENT_BY_ROW + aci_NUM);
echo "$nrows rows fetched<br>\n";
var_dump($res);
// Output is:
// 2 rows fetched
// array(2) {
// [0]=>
// array(2) {
// [0]=>
// string(6) "00989x"
// [1]=>
// string(4) "Roma"
// }
// [1]=>
// array(2) {
// [0]=>
// string(6) "10934x"
// [1]=>
// string(6) "Venice"
// }
// }
aci_free_statement($stid);
aci_close($conn);
?>
注释¶
注意:
使用跳过非常低效。所有要跳过的行都包含在从数据库返回到PHP的结果集中。然后将其丢弃。使用SQL来限制查询中的偏移量和行范围更有效。有关示例,请参见aci_fetch_array()。
注意:
如果使用像aci_fetch_array()这样的单行提取函数,则返回大量行的查询可以更节省内存。
注意:
查询返回巨大数量的数据行时,通过增大 oci8.默认_预取值或使用 aci_set_prefetch()可显著提高性能。
注意:
在5.0.0之前的PHP版本中,必须改用cifetchstatement()。
参数¶
aci_fetch()-将下一行提取到结果缓冲区
aci_fetch_array()-以关联数组或数字数组的形式返回查询的下一行
aci_fetch_assoc()-将查询的下一行作为关联数组返回
aci_fetch_object()-将查询的下一行作为对象返回
aci_fetch_row()-以数字数组形式返回查询的下一行
aci_set_prefetch()-设置预提取行数