Re: display query results

From: Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>
To: pgsql-php(at)postgresql(dot)org
Cc: PJ <af(dot)gourmet(at)videotron(dot)ca>
Subject: Re: display query results
Date: 2008-07-30 16:38:39
Message-ID: 200807301238.39714.xzilla@users.sourceforge.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-php

On Wednesday 30 July 2008 12:18:28 PJ wrote:
> 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?

pg_query just gives you a pointer to the result set, to get the actual
information in the result, you need to use one of the other pg_ functions to
grab that. ie. http://us.php.net/manual/en/function.pg-fetch-result.php (and
about a dozen others)

--
Robert Treat
Build A Brighter LAMP :: Linux Apache {middleware} PostgreSQL

In response to

Browse pgsql-php by date

  From Date Subject
Next Message PJ 2008-07-30 17:44:17 Re: display query results
Previous Message Matthias Ritzkowski 2008-07-30 16:35:34 Re: display query results