PHP Manual
Prev |  | Next

# pg_Fetch_Array

pg_Fetch_Array -- fetch row as array

## Description

`array pg_fetch_array`(int result, int row, int [result_type] );

Returns: An array that corresponds to the fetched row, or false if there are no more rows.

pg_fetch_array() is an extended version of pg_fetch_row(). In addition to storing the data in the numeric indices of the result array, it also stores the data in associative indices, using the field names as keys.

The third optional argument `result_type` in pg_fetch_array() is a constant and can take the following values: PGSQL_ASSOC, PGSQL_NUM, and PGSQL_BOTH.

> Note: `Result_type` was added in PHP 4.0.

An important thing to note is that using pg_fetch_array() is NOT significantly slower than using pg_fetch_row(), while it provides a significant added value.

For further details, also see pg_fetch_row()

Example 1. PostgreSQL fetch array
      1
      2 <?php
      3 $conn = pg_pconnect("","","","","publisher");
      4 if (!$conn) {
      5     echo "An error occured.\n";
      6     exit;
      7 }
      8
      9 $result = pg_Exec ($conn, "SELECT * FROM authors");
     10 if (!$result) {
     11     echo "An error occured.\n";
     12     exit;
     13 }
     14
     15 $arr = pg_fetch_array ($result, 0);
     16 echo $arr[0] . " <- array\n";
     17
     18 $arr = pg_fetch_array ($result, 1);
     19 echo $arr["author"] . " <- array\n";
     20 ?>
     21

Prev | Home | Next
pg_Exec | Up | pg_Fetch_Object