Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id DF2B56500D1 for ; Wed, 30 Jul 2008 13:38:55 -0300 (ADT) Received: from postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 81840-03 for ; Wed, 30 Jul 2008 13:38:51 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from vms046pub.verizon.net (vms046pub.verizon.net [206.46.252.46]) by postgresql.org (Postfix) with ESMTP id 4810A64FFC0 for ; Wed, 30 Jul 2008 13:38:52 -0300 (ADT) Received: from ridley.home ([71.179.100.114]) by vms046.mailsrvcs.net (Sun Java System Messaging Server 6.2-6.01 (built Apr 3 2006)) with ESMTPA id <0K4T00KU5VKG0WV2@vms046.mailsrvcs.net> for pgsql-php@postgresql.org; Wed, 30 Jul 2008 11:38:40 -0500 (CDT) Date: Wed, 30 Jul 2008 12:38:39 -0400 From: Robert Treat Subject: Re: display query results In-reply-to: <48909454.7040305@videotron.ca> To: pgsql-php@postgresql.org Cc: PJ Message-id: <200807301238.39714.xzilla@users.sourceforge.net> MIME-version: 1.0 Content-type: text/plain; charset=iso-8859-1 Content-transfer-encoding: 7bit Content-disposition: inline References: <48909454.7040305@videotron.ca> User-Agent: KMail/1.9.9 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200807/3 X-Sequence-Number: 3867 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