pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PJ <af.gourmet@videotron.ca>
To: Spiegelberg, Greg <gspiegelberg@isodxsolutions.com>
Cc: pgsql-php@postgresql.org
Subject: Re: display query results
Date: Wed, 30 Jul 2008 13:44:17 -0400
Message-ID: <4890A871.3020906@videotron.ca> (raw)
In-Reply-To: <82E74D266CB9B44390D3CCE44A781ED90B64DC@POSTOFFICE.cranel.local>
References: <48909454.7040305@videotron.ca>
	<82E74D266CB9B44390D3CCE44A781ED90B64DC@POSTOFFICE.cranel.local>

I've been looking at the pg_fetch_* functions but do not understand one 
little bit.
Using your suggestion gives a blank screen but var_dump($myarray) gives 
"bool(false)"
And a var_dump($results) returns "resource(3) of type (pgsql result) 
while print_r($results) returns "Resource id#3"
I'm totally lost. :(
Perhaps my query isn't well formulated?
What I am trying to locate (or print out) is the string found the 
"description" column whre the row in the "name" column is Alcohol.
item_id  ||  glossary_id ||  name     || description
2           ||        2          || Alcohol  || One of thetwo major.... 
blah...blah.. blah  

Spiegelberg, Greg wrote:
> You need to fetch the results.  See the pg_fetch_* family of functions 
> for the one of your liking.
>  
>  $myarray = pg_fetch_all($results);
>  print_r($myarray);
>  
> Greg
>
> ------------------------------------------------------------------------
> *From:* pgsql-php-owner@postgresql.org on behalf of PJ
> *Sent:* Wed 7/30/2008 10:18 AM
> *To:* pgsql-php@postgresql.org
> *Subject:* [PHP] display query results
>
> I am trying to learn postgresql with psql - using FreeBS D7.0,
> postgresql 8.3.3 php 5.2.6, apache 2.2.9
>
> How can I echo or print on screen the results; all I get from this code
> is this:
> Resource id #3
> item_idglossary_idnamedescription
> which is the field names run together
>
> I am expecting to see several long text sentences.
>
> Here is the snippet and the connection does work and the database is
> there and functioning.
>
>         $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
>         echo "$result";
>
>         pg_close($db);
>
> What am I doing wrong?
>



view thread (21+ messages)  latest in thread

Message-ID: <4890A871.3020906@videotron.ca>
Permalink:  ../4890A871.3020906@videotron.ca/
Also on:    postgresql.org/message-id/4890A871.3020906@videotron.ca

 · 

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: af.gourmet@videotron.ca, gspiegelberg@isodxsolutions.com
  Subject: Re: display query results
  In-Reply-To: <4890A871.3020906@videotron.ca>
  References: <48909454.7040305@videotron.ca> <82E74D266CB9B44390D3CCE44A781ED90B64DC@POSTOFFICE.cranel.local> <4890A871.3020906@videotron.ca>

* 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