(PHP 4, PHP 5, PHP 7, PHP 8)
pg_fetch_row — Lee una fila en un array
pg_fetch_row() lee una fila en el resultado
asociado a la instancia 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).
row
Número de la fila a recuperar. Las filas están numeradas
comenzando en 0. Si el argumento es omitido o si vale null
,
la siguiente fila es recuperada.
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 de tipo array, indexado desde 0, con cada
valor representado como un string (string).
Los valores null
de la base de datos son retornados como null
.
false
es retornado si row
excede el número de
filas en el conjunto de resultados, no tiene más filas disponibles o cualquier
otro error.
Versión | Descripción |
---|---|
8.1.0 |
The result parameter expects an PgSql\Result
instance now; previously, a recurso was expected.
|
Ejemplo #1 Ejemplo con pg_fetch_row()
<?php
$conn = pg_pconnect("dbname=publisher");
if (!$conn) {
echo "Ha ocurrido un error.\n";
exit;
}
$result = pg_query($conn, "SELECT autor, email FROM autores");
if (!$result) {
echo "Ha ocurrido un error.\n";
exit;
}
while ($row = pg_fetch_row($result)) {
echo "Autor: $row[0] E-mail: $row[1]";
echo "<br />\n";
}
?>