PHP.nl

pg_fetch_all

pg_fetch_all

Fetches all rows from a result as an array

array **pg_fetch_all** PgSql\Result $result int $mode
returns an array that

contains all rows (records) in the instance. pg_fetch_all``PgSql\Result

result``mode

An with all rows in the result. Each row is an array of field values indexed by field name. array

Voorbeeld: PostgreSQL fetch all

<?php 
$conn = pg_pconnect("dbname=publisher");
if (!$conn) {
    echo "An error occurred.\n";
    exit;
}

$result = pg_query($conn, "SELECT * FROM authors");
if (!$result) {
    echo "An error occurred.\n";
    exit;
}

$arr = pg_fetch_all($result);

print_r($arr);

?>
Array
(
    [0] => Array
        (
            [id] => 1
            [name] => Fred
        )

    [1] => Array
        (
            [id] => 2
            [name] => Bob
        )

)

pg_fetch_row``pg_fetch_array``pg_fetch_object``pg_fetch_result