pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Raymond O'Donnell <rod@iol.ie>
To: PJ <af.gourmet@videotron.ca>
Cc: Matthias Ritzkowski <matthiar@gmail.com>
Cc: pgsql-php@postgresql.org
Subject: Re: display query results
Date: Wed, 30 Jul 2008 19:44:09 +0100
Message-ID: <4890B679.9010301@iol.ie> (raw)
In-Reply-To: <4890A983.2040005@videotron.ca>
References: <48909454.7040305@videotron.ca>
	<b73498770807300935o6045679aq4dcedf6ffd073a2d@mail.gmail.com>
	<4890A983.2040005@videotron.ca>

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@iol.ie
Galway Cathedral Recitals: http://www.galwaycathedral.org/recitals
------------------------------------------------------------------



view thread (21+ messages)  latest in thread

Message-ID: <4890B679.9010301@iol.ie>
Permalink:  ../4890B679.9010301@iol.ie/
Also on:    postgresql.org/message-id/4890B679.9010301@iol.ie

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-php@postgresql.org
  Cc: rod@iol.ie, af.gourmet@videotron.ca, matthiar@gmail.com
  Subject: Re: display query results
  In-Reply-To: <4890B679.9010301@iol.ie>
  References: <48909454.7040305@videotron.ca> <b73498770807300935o6045679aq4dcedf6ffd073a2d@mail.gmail.com> <4890A983.2040005@videotron.ca> <4890B679.9010301@iol.ie>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox