array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'pt_BR', ), 'this' => array ( 0 => 'function.pg-fetch-all.php', 1 => 'pg_fetch_all', ), 'up' => array ( 0 => 'ref.pgsql.php', 1 => 'Funções PostgreSQL', ), 'prev' => array ( 0 => 'function.pg-fetch-all-columns.php', 1 => 'pg_fetch_all_columns', ), 'next' => array ( 0 => 'function.pg-fetch-array.php', 1 => 'pg_fetch_array', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/pgsql/functions/pg-fetch-all.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8)
pg_fetch_all — Fetches all rows from a result as an array
pg_fetch_all() returns an array that contains all rows (records) in the PgSql\Result instance.
Nota: Esta função define campos NULL como o valor
null
do PHP.
result
Uma instância de PgSql\Result, retornada por pg_query(), pg_query_params() ou pg_execute() (entre outras).
mode
Um parâmetro opcional que controla como o array retornado será indexado.
mode
é uma constante e pode assumir os seguintes valores:
PGSQL_ASSOC
, PGSQL_NUM
e PGSQL_BOTH
.
Usando PGSQL_NUM
, a função retornará um array com índices numéricos,
usando PGSQL_ASSOC
ela retornará apenas índices associativos
enquanto PGSQL_BOTH
retornará índices numéricos e associativos.
An array with all rows in the result. Each row is an array of field values indexed by field name.
Versão | Descrição |
---|---|
8.1.0 |
O parâmetro result agora espera uma instância de PgSql\Result;
anteriormente, um resource era esperado.
|
8.0.0 |
pg_fetch_all() will now return an empty array
instead of false for result sets with zero rows.
|
7.1.0 |
The mode parameter was added.
|
Exemplo #1 PostgreSQL fetch all
<?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);
?>
O exemplo acima produzirá algo semelhante a:
Array ( [0] => Array ( [id] => 1 [name] => Fred ) [1] => Array ( [id] => 2 [name] => Bob ) )