Comunitatea PHP Romania
 

 
pg_fetch_array

pg_fetch_array

(PHP 3>= 3.0.1, PHP 4 , PHP 5)

pg_fetch_array -- Fetch a row as an array

Description

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

pg_fetch_array() returns an array that corresponds to the fetched row (tuples/records). It returns 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 (field index) to the result array, it also stores the data in associative indices (field name) by default.

row is row (record) number to be retrieved. First row is 0.

result_type is an optional parameter that controls how the return value is initialized. result_type is a constant and can take the following values: PGSQL_ASSOC, PGSQL_NUM, and PGSQL_BOTH. pg_fetch_array() returns associative array that has field name as key for PGSQL_ASSOC, field index as key with PGSQL_NUM and both field name/index as key with PGSQL_BOTH. Default is PGSQL_BOTH.

Notã: result_type was added in PHP 4.0.

pg_fetch_array() is NOT significantly slower than using pg_fetch_row(), while it provides a significant ease of use.

Exemplu 1. pg_fetch_array() example

<?php

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

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

$arr = pg_fetch_array($result, 0, PGSQL_NUM);
echo
$arr[0] . " <- array\n";

$arr = pg_fetch_array($result, 1, PGSQL_ASSOC);
echo
$arr["author"] . " <- array\n";

?>

Notã: From 4.1.0, row became optional. Calling pg_fetch_array() will increment internal row counter by 1.

See also pg_fetch_row(), pg_fetch_object() and pg_fetch_result().

Ultimele discutii in forum RSS Forum

Ultimele articole Ultimele articole

Top membri

Pirahna Pirahna
la birou
carco carco
Bucuresti
Birkoff Birkoff
Bucuresti
Mascka Mascka
Braila
raul_ raul_
whooper whooper
Toronto ON
mihaitha mihaitha
Sibiu
gabysolomon gabysolomon
Bacau
oriceon oriceon
Constanta
garlicinicolae garlicinicolae

Newsletter


Email:
 inscriere
 renuntare
 
 Arhiva newsletter

Parteneriat

Copyright © 2001-2008 PHP Romania Add PHPRomania to Google Add PHPRomania to Del.icio.us Add PHPRomania to Stumbleupon Add PHPRomania to Yahoo! Add PHPRomania to Digg Add PHPRomania to Blink Proliant Server Memory | Credit Counseling | Novela romantica | Lincoln LS | Debt Help
Ads: Partener Way2Web Nework: gazduire web | inregistrare domenii | web design | imobiliare | web hosting
Powered by Simplis