Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 406E164FD8D for ; Wed, 12 Nov 2008 05:03:10 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 40276-03 for ; Wed, 12 Nov 2008 05:03:07 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail.morphoss.com (hoppy.mcmillan.net.nz [202.78.240.82]) by mail.postgresql.org (Postfix) with ESMTP id E50CE64FD45 for ; Wed, 12 Nov 2008 05:03:06 -0400 (AST) Received: from [IPv6:2404:130:b055:0:215:afff:fe48:6c48] (unknown [IPv6:2404:130:b055:0:215:afff:fe48:6c48]) by mail.morphoss.com (Postfix) with ESMTPS id 9967922F2A; Wed, 12 Nov 2008 22:03:01 +1300 (NZDT) Subject: Re: See postgre tables from PHP code From: Andrew McMillan To: =?ISO-8859-1?Q?F=E9lix_S=E1nchez_?= =?ISO-8859-1?Q?Rodr=EDguez?= Cc: PostgreSQLPHP In-Reply-To: <001501c942e9$665772b0$3000a8c0@atenea> (sfid-20081112_152739_398410_0B4FA913) References: <001501c942e9$665772b0$3000a8c0@atenea> (sfid-20081112_152739_398410_0B4FA913) Content-Type: text/plain; charset=utf-8 Date: Wed, 12 Nov 2008 22:03:00 +1300 Message-Id: <1226480580.6868.246.camel@happy.mcmillan.net.nz> Mime-Version: 1.0 X-Mailer: Evolution 2.22.3.1 Content-Transfer-Encoding: 8bit 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: 200811/8 X-Sequence-Number: 3919 On Mon, 2008-11-10 at 05:04 +0100, Félix Sánchez Rodríguez wrote: > Hi everybody: > > I'm relatively new to PHP programming and I was recommended to use > PostgreSQL as the site's database. However I haven't able to see my DB's > tables from PHP. Here is my (very simple, I think) code: > > $pg = pg_connect("host=localhost port =5432 dbaname = ATM user=postgres > password = mypassword"); > pg_query($pg,"select nick,contrasenna,nombre,apellidos from usuarios"); > > Beside, I opened my PostgreSQL interface, called pgAdmin and run the same > query inside the ATM database and the error was the same: "relation > 'usuarios' was not found". It's like something else was needed to access the > DB tables. Is it possible that the tables are in a different schema? For example, on a Mediawiki installation I have: davical_wiki=# \d No relations found. davical_wiki=# set search_path TO 'mediawiki'; SET davical_wiki=# \d List of relations Schema | Name | Type | Owner -----------+-----------------------+----------+------------------ mediawiki | archive | table | davical_wikiuser mediawiki | category | table | davical_wikiuser mediawiki | category_id_seq | sequence | davical_wikiuser ... You can refer to tables in a different schema by prefixing the table name with the schema name and '.', e.g. mediawiki.archive davical_wiki=# \d mediawiki.archive Table "mediawiki.archive" Column | Type | Modifiers ---------------+--------------------------+-------------------- ar_namespace | smallint | not null ar_title | text | not null ... The same prefixing syntax should work. The same 'set search_path ...' syntax should also work if you do that after the pg_connect call. If you're in psql, too, tab-completion should work, so if you go \d you will see a list of schema, like: davical_wiki=# \d information_schema. pg_catalog. pg_toast. public. mediawiki. pg_temp_1. pg_toast_temp_1. If I did that after setting the search path the autocomplete finds all the tables in the mediawiki schema also. Cheers, Andrew. ------------------------------------------------------------------------ andrew (AT) morphoss (DOT) com +64(272)DEBIAN Q: How much does it cost to ride the Unibus? A: 2 bits. ------------------------------------------------------------------------