array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'pt_BR', ), 'this' => array ( 0 => 'function.pg-fetch-result.php', 1 => 'pg_fetch_result', ), 'up' => array ( 0 => 'ref.pgsql.php', 1 => 'Funções 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' => 'en', '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 — Returns values from a result instance
pg_fetch_result() returns the value of a particular row and field (column) in an PgSql\Result instance.
Nota:
This function used to be called pg_result().
result
Uma instância de PgSql\Result, retornada por pg_query(), pg_query_params() ou pg_execute() (entre outras).
row
Row number in result to fetch. Rows are numbered from 0 upwards. If omitted, next row is fetched.
field
A string representing the name of the field (column) to fetch, otherwise an int representing the field number to fetch. Fields are numbered from 0 upwards.
Boolean is returned as "t" or "f". All
other types, including arrays are returned as strings formatted
in the same default PostgreSQL manner that you would see in the
psql program. Database NULL
values are returned as null
.
false
is returned if row
exceeds the number
of rows in the set, or on any other error.
Versão | Descrição |
---|---|
8.3.0 |
row is now nullable.
|
8.1.0 |
O parâmetro result agora espera uma instância de PgSql\Result;
anteriormente, um resource era esperado.
|
Exemplo #1 pg_fetch_result() example
<?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";
?>
O exemplo acima produzirá:
First field in the second row is: 2