pg_fetch_row
(PHP 4, PHP 5, PHP 7, PHP 8)
pg_fetch_row — 提取一行作为枚举数组
说明
pg_fetch_row() 根据指定 result 实例提取一行数据(记录)作为数组返回。每个得到的列依次存放在数组中,偏移量从 0 开始。
注意: 此函数将 NULL 字段设置为 PHP
null值。
参数
result-
PgSql\Result 实例,由 pg_query()、pg_query_params() 或者 pg_execute()(等)返回。
row-
要获取的结果中的行号。行从 0 向上编号。如果省略或为
null,则获取下一行。 mode-
An optional parameter that controls how the returned array is indexed.
modeis a constant and can take the following values:PGSQL_ASSOC,PGSQL_NUMandPGSQL_BOTH. UsingPGSQL_NUM, the function will return an array with numerical indices, usingPGSQL_ASSOCit will return only associative indices whilePGSQL_BOTHwill return both numerical and associative indices.
更新日志
| 版本 | 说明 |
|---|---|
| 8.1.0 |
现在 result 参数接受 PgSql\Result
实例,之前接受 resource。
|
示例
示例 #1 pg_fetch_row() 示例
<?php
$conn = pg_pconnect("dbname=publisher");
if (!$conn) {
echo "An error occurred.\n";
exit;
}
$result = pg_query($conn, "SELECT author, email FROM authors");
if (!$result) {
echo "An error occurred.\n";
exit;
}
while ($row = pg_fetch_row($result)) {
echo "Author: $row[0] E-mail: $row[1]";
echo "<br />\n";
}
?>参见
- pg_query() - 执行查询
- pg_fetch_array() - 获取一行作为数组
- pg_fetch_object() - 获取一行作为对象
- pg_fetch_result() - 从结果实例返回值