PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8
pg_fetch_all - Fetches all rows from a result as an array
Code Examples

pg_fetch_all( PgSql\Result$result, [int$mode = PGSQL_ASSOC] ): array

pg_fetch_all returns an array that contains all rows (records) in the PgSql\Result instance.


This function sets NULL fields to the PHP null value.



An PgSql\Result instance, returned by pg_query, pg_query_params or pg_execute(among others).


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, pg_fetch_all 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 with all rows in the result. Each row is an array of field values indexed by field name.


Version Description
8.1.0 The result parameter expects an PgSql\Result instance now; previously, a resource was expected.
7.1.0 The mode parameter was added.

Related Functions

Example of pg_fetch_all

Show all examples for pg_fetch_all

PHP Version:

Function pg_fetch_all:

PostgreSQL Functions

Most used PHP functions