pg_fetch_array
pg_fetch_array
Fetch a row as an array
**pg_fetch_array** PgSql\Result $result $row int $mode
returns an array that
corresponds to the fetched row (record).
pg_fetch_array
is an extended version of
. In addition to storing the
data in the numeric indices (field number) to the result array, it
can also store the data using associative indices (field name).
It stores both indices by default.
pg_fetch_array``pg_fetch_row
is NOT significantly
slower than using , and
is significantly easier to use.
pg_fetch_array``pg_fetch_row
result``rowRow number in result to fetch. Rows are numbered from 0 upwards. If
omitted or null, the next row is fetched.
mode
An indexed numerically (beginning with 0) or
associatively (indexed by field name), or both.
Each value in the is represented as a
. Database
values are returned as null.
array``array``string``NULL
false is returned if exceeds the number
of rows in the set, there are no more rows, or on any other error.
Fetching from the result of a query other than SELECT will also return false.
row
Voorbeeld: example
<?php
$conn = pg_pconnect("dbname=publisher");
if (!$conn) {
echo "An error occurred.\n";
exit;
}
$result = pg_query($conn, "SELECT author, email FROM authors");
if (!$result) {
echo "An error occurred.\n";
exit;
}
$arr = pg_fetch_array($result, 0, PGSQL_NUM);
echo $arr[0] . " <- Row 1 Author\n";
echo $arr[1] . " <- Row 1 E-mail\n";
// The row parameter is optional; NULL can be passed instead,
// to pass a result_type. Successive calls to pg_fetch_array
// will return the next row.
$arr = pg_fetch_array($result, NULL, PGSQL_ASSOC);
echo $arr["author"] . " <- Row 2 Author\n";
echo $arr["email"] . " <- Row 2 E-mail\n";
$arr = pg_fetch_array($result);
echo $arr["author"] . " <- Row 3 Author\n";
echo $arr[1] . " <- Row 3 E-mail\n";
?>
pg_fetch_row``pg_fetch_object``pg_fetch_result