(PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8)
pg_fetch_all — 从结果中获取所有行作为数组
resultPgSql\Result 实例,由 pg_query()、pg_query_params() 或者 pg_execute()(等)返回。
mode
An optional parameter that controls how the returned array is indexed.
mode is a constant and can take the following values:
PGSQL_ASSOC, PGSQL_NUM and PGSQL_BOTH.
Using PGSQL_NUM, the function will return an array with numerical indices,
using PGSQL_ASSOC it will return only associative indices
while PGSQL_BOTH will return both numerical and associative indices.
包含结果中所有行的 array。每行都是一个由字段名作为索引的字段值数组。
| 版本 | 说明 |
|---|---|
| 8.1.0 |
现在 result 参数接受 PgSql\Result
实例,之前接受 资源(resource)。
|
| 8.0.0 | 对于零行的结果集,pg_fetch_all() 现在将返回一个空数组而不是 array。 |
| 7.1.0 |
新增 mode 参数。
|
示例 #1 PostgreSQL 获取全部
<?php
$conn = pg_pconnect("dbname=publisher");
if (!$conn) {
echo "An error occurred.\n";
exit;
}
$result = pg_query($conn, "SELECT * FROM authors");
if (!$result) {
echo "An error occurred.\n";
exit;
}
$arr = pg_fetch_all($result);
print_r($arr);
?>
以上例程的输出类似于:
Array
(
[0] => Array
(
[id] => 1
[name] => Fred
)
[1] => Array
(
[id] => 2
[name] => Bob
)
)