★ wanayoo — archive 1999 http://www.php.net/manual/function.pg-fetch-array.phpNouvelle recherche | Portail wanayoo

PHP Home Page

Manual Table of Contents
Up to PostgreSQL
Quick Reference
German version of this pageJapanese version of this pageItalian version of this pageFrench version of this pageHungarian version of this page
PostgreSQL
* pg_close
* pg_cmdtuples
* pg_connect
* pg_dbname
* pg_errormessage
* pg_exec
* pg_fetch_array
* pg_fetch_object
* pg_fetch_row
* pg_fieldisnull
* pg_fieldname
* pg_fieldnum
* pg_fieldprtlen
* pg_fieldsize
* pg_fieldtype
* pg_freeresult
* pg_getlastoid
* pg_host
* pg_loclose
* pg_locreate
* pg_loexport
* pg_loimport
* pg_loopen
* pg_loread
* pg_loreadall
* pg_lounlink
* pg_lowrite
* pg_numfields
* pg_numrows
* pg_options
* pg_pconnect
* pg_port
* pg_result
* pg_trace
* pg_tty
* pg_untrace
Manual: pg_fetch_array
View the source code for this pageSearch the site



Previous page
 pg_exec
 Updated
Sat, 12 Aug 2000
pg_fetch_object 
Next page


pg_fetch_array

(PHP3 >= 3.0.1, PHP4 )

pg_fetch_array -- Fetch a row as an 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, see also pg_fetch_row()

Example 1. PostgreSQL fetch array


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

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

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

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

User Contributed Notes: pg_fetch_array


henrry@rocketmail.com
31-Jul-2000 05:03
I have a little problem with your pg_fetch_array. Sometimes get this message : "Warning: Unable to jump to row 3 on PostgresSQL result index 2 in database.php on line 65". And sometimes the warning didn't appear. I just could fix it. My source program is :
function Select_db ($db_nama,$syn_SQL,$n_field)
{
$hasil_qry=pg_exec($db_nama,$syn_SQL);
$row=0;
while($data=pg_fetch_array($hasil_qry,$row)):
for($i=0;$i<$n_field;$i++)
echo $data[$i]." ";
echo "
";
$row++;
endwhile;
}
Could anyone tell me what the problem ?



ecestari@hotmail.Com
04-Aug-2000 09:25
It is because $row is incremented one time too many. Try instead :

$result=pg_exec($handle,$query);

$row=0;

$max_row=pg_numrows($result);

while($row < $max_row) {

$data=pg_fetch_object($result,$row);

///Some more code

}

And you'll get rid of those error messages
c*



 About Notes


Previous page
 pg_exec
 Updated
Sat, 12 Aug 2000
pg_fetch_object 
Next page





Who's responsible for this?
Top of this page

Site
Hosting:



Located in
United States
Elements of this website are subject to copyright.
Questions about installing or using PHP should be directed to one of the mailing lists.
Only questions about the website should be directed to webmaster@php.net.