pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Matthias Ritzkowski <matthiar@gmail.com>
To: PJ <af.gourmet@videotron.ca>
Cc: pgsql-php@postgresql.org
Subject: Re: display query results
Date: Wed, 30 Jul 2008 12:35:34 -0400
Message-ID: <b73498770807300935o6045679aq4dcedf6ffd073a2d@mail.gmail.com> (raw)
In-Reply-To: <48909454.7040305@videotron.ca>
References: <48909454.7040305@videotron.ca>

Try this:

$db = pg_connect("host=localhost port=5432 dbname=med user=med
password=0tscc71");

         if (!$db)
         {
         die("Could not open connection to database server");
         }

          // generate and execute a query
         $query = "SELECT description FROM glossary_item WHERE
 name='Alcohol'";
         $result = pg_query($db, $query) or die("Error in query: $query.
         " . pg_last_error($db));

         // Print result on screen
while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) {
   foreach ($line as $col_value) {
        echo $col_value."<br />";
    }

         pg_close($db);


The result set is an array, You just need to loop through it. The php
manual has some nice examples that helped me get started.
--------------------------------


Matthias Ritzkowski



view thread (21+ messages)  latest in thread

Message-ID: <b73498770807300935o6045679aq4dcedf6ffd073a2d@mail.gmail.com>
Permalink:  ../b73498770807300935o6045679aq4dcedf6ffd073a2d@mail.gmail.com/
Also on:    postgresql.org/message-id/b73498770807300935o6045679aq4dcedf6ffd073a2d@mail.gmail.com

 · 

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: matthiar@gmail.com, af.gourmet@videotron.ca
  Subject: Re: display query results
  In-Reply-To: <b73498770807300935o6045679aq4dcedf6ffd073a2d@mail.gmail.com>
  References: <48909454.7040305@videotron.ca> <b73498770807300935o6045679aq4dcedf6ffd073a2d@mail.gmail.com>

* 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