update : 2015.11.03
php.shukuma.com

검색:
 
 
Fetches all rows from a result as an array

pg_fetch_all

(PHP 4 >= 4.3.0, PHP 5)

pg_fetch_allFetches all rows from a result as an array

설명

array pg_fetch_all ( resource $result )

pg_fetch_all() returns an array that contains all rows (records) in the result resource.

Note: 이 함수는 NULL 필드를 PHP NULL 값으로 설정합니다.

인수

result

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

반환값

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

FALSE is returned if there are no rows in the result, or on any other error.

예제

Example #1 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
        )

)

참고