(PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8)
pg_fetch_all — Lee todas las líneas de un resultado
pg_fetch_all() devuelve un array que contiene
todas las líneas de result
.
Nota: Esta función define campos NULOS al valor
null
de PHP.
result
An PgSql\Result instance, returned by pg_query(), pg_query_params() or pg_execute()(among others).
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.
Un array array de todas las líneas en el conjunto de resultados. Cada línea es un array de valores de los campos indexado por el nombre de los campos.
Versión | Descripción |
---|---|
8.1.0 |
The result parameter expects an PgSql\Result
instance now; previously, a recurso was expected.
|
8.0.0 |
pg_fetch_all() devolverá ahora un tableau vacío
en lugar de false para los conjuntos de resultados con cero líneas.
|
7.1.0 |
Se ha añadido el argumento mode .
|
Ejemplo #1 Ejemplo con pg_fetch_all()
<?php
$conn = pg_pconnect("dbname=publisher");
if (!$conn) {
echo "Se ha producido un error.\n";
exit;
}
$result = pg_query($conn, "SELECT * FROM autores");
if (!$result) {
echo "Se ha producido un error.\n";
exit;
}
$arr = pg_fetch_all($result);
print_r($arr);
?>
El resultado del ejemplo sería algo similar a:
Array ( [0] => Array ( [id] => 1 [name] => Fred ) [1] => Array ( [id] => 2 [name] => Bob ) )