IMPRESS dotted_line CONTACT dotted_line search dotted_line Kontakt dotted_line sitemap dotted_line print
115 PHP-Resource users online

Switch to another languags Deutsch aktuelle Sprache Englisch

PHP Manual


(PHP 4, PHP 5)

pg_fetch_arrayFetch a row as an array


array pg_fetch_array ( resource $result [, int $row [, int $result_type = PGSQL_BOTH ]] )

pg_fetch_array() returns an array that corresponds to the fetched row (record).

pg_fetch_array() is an extended version of pg_fetch_row(). 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 indicies by default.

Note: This function sets NULL fields to the PHP NULL value.

pg_fetch_array() is NOT significantly slower than using pg_fetch_row(), and is significantly easier to use.



PostgreSQL query result resource, returned by pg_query(), pg_query_params() or pg_execute() (among others).


Row number in result to fetch. Rows are numbered from 0 upwards. If omitted or NULL, the next row is fetched.


An optional parameter that controls how the returned array is indexed. result_type is a constant and can take the following values: PGSQL_ASSOC, PGSQL_NUM and PGSQL_BOTH. Using PGSQL_NUM, pg_fetch_array() will return an array with numerical indices, using PGSQL_ASSOC it will return only associative indices while PGSQL_BOTH, the default, will return both numerical and associative indices.

Return Values

An array indexed numerically (beginning with 0) or associatively (indexed by field name), or both. Each value in the array is represented as a string. Database NULL values are returned as NULL.

FALSE is returned if row exceeds the number of rows in the set, there are no more rows, or on any other error.


Version Description
4.1.0 The row parameter became optional.


Example #1 pg_fetch_array() example


if (!
$conn) {
"An error occured.\n";

$result pg_query($conn"SELECT author, email FROM authors");
if (!
$result) {
"An error occured.\n";

$arr pg_fetch_array($result0PGSQL_NUM);
$arr[0] . " <- Row 1 Author\n";
$arr[1] . " <- Row 1 E-mail\n";

// As of PHP 4.1.0, 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($resultNULLPGSQL_ASSOC);
$arr["author"] . " <- Row 2 Author\n";
$arr["email"] . " <- Row 2 E-mail\n";

$arr pg_fetch_array($result);
$arr["author"] . " <- Row 3 Author\n";
$arr[1] . " <- Row 3 E-mail\n";


See Also

Comments to the PHP manual
Write new comment


New Tutorial entries

Migration einer PHP 5 App auf PHP 7

Dieses PHP 7 Tutorial zeigt dir, wie du dein PHP5 Script auf PHP7 umstellst.

Berni | Category: PHP
PHP 7 Virtual Machine

Dieser Artikel zielt darauf ab, einen Überblick über die Zend Virtual Machine, wie es in PHP 7 gefunden wird.

Berni | Category: PHP
plotting masters - a professional guide - Teil II

Grafische Interpolation und Bestapproximation von numerischen Wertepaaren: Wir wollen Punkte auf einer Zeichenebene über verschiedene Verfahren miteinander verbinden.

EVAMasters | Category: PHP