array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'function.pg-fetch-result.php', 1 => 'pg_fetch_result', ), 'up' => array ( 0 => 'ref.pgsql.php', 1 => 'PostgreSQL 函数', ), 'prev' => array ( 0 => 'function.pg-fetch-object.php', 1 => 'pg_fetch_object', ), 'next' => array ( 0 => 'function.pg-fetch-row.php', 1 => 'pg_fetch_row', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'zh', 'path' => 'reference/pgsql/functions/pg-fetch-result.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8)
pg_fetch_result — 从结果实例返回值
result
PgSql\Result 实例,由 pg_query()、pg_query_params() 或者 pg_execute()(等)返回。
row
要获取的结果中的行号。行从 0 向上编号。如果省略,则获取下一行。
field
布尔值返回为 "t" 或 "f"。所有其它类型,包括数组,都以字符串形式返回,其格式与 psql
程序中的 PostgreSQL 默认方式相同。数据库 NULL
值作为 null
返回。
如果 row
超过集合中的行数或任何其他错误,则返回 false
。
版本 | 说明 |
---|---|
8.3.0 |
row 现在可为 null。
|
8.1.0 |
现在 result 参数接受 PgSql\Result
实例,之前接受 resource。
|
示例 #1 pg_fetch_result() 示例
<?php
$db = pg_connect("dbname=users user=me") || die();
$res = pg_query($db, "SELECT 1 UNION ALL SELECT 2");
$val = pg_fetch_result($res, 1, 0);
echo "First field in the second row is: ", $val, "\n";
?>
以上示例会输出:
First field in the second row is: 2