From: | Raymond O'Donnell <rod(at)iol(dot)ie> |
---|---|
To: | PJ <af(dot)gourmet(at)videotron(dot)ca> |
Cc: | Matthias Ritzkowski <matthiar(at)gmail(dot)com>, pgsql-php(at)postgresql(dot)org |
Subject: | Re: display query results |
Date: | 2008-07-30 18:44:09 |
Message-ID: | 4890B679.9010301@iol.ie |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-php |
On 30/07/2008 18:48, PJ wrote:
> Doesn't work... and I feel totally lost. I don't understand the
> pg_fetch_* stuff at all.
Here's what you need to do:
// Open a connection to the database.
$conn = pg_connect($your_connection_string);
// Execute a query which returns some rows.
$result = pg_query($conn, 'select foo, bar from your_table');
// Loop through the rows one by one.
// pg_fetch_array() returns the row as an array with a numeric index,
// while pg_fetch_assoc() returns the row as an associative array
// keyed on the column names. I usually use the latter. Both return
// false when no more rows are available, so this is the usual idiom:
while ($row = pg_fetch_assoc($result))
{
print 'Some values: ' . $row['foo'] . ', ' . $row['bar'] . "\n";
}
The other pg_fetch_* functions do various other things, such as (for
example) fetching a value from a particular column in a particular row.
HTH,
Ray.
------------------------------------------------------------------
Raymond O'Donnell, Director of Music, Galway Cathedral, Ireland
rod(at)iol(dot)ie
Galway Cathedral Recitals: http://www.galwaycathedral.org/recitals
------------------------------------------------------------------
From | Date | Subject | |
---|---|---|---|
Next Message | PJ | 2008-07-30 20:07:35 | Re: display query results |
Previous Message | Lynna Landstreet | 2008-07-30 17:53:16 | Re: display query results |