pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andrew McMillan <andrew@morphoss.com>
To: Félix Sánchez Rodríguez <fesanch@ciego.cult.cu>
Cc: PostgreSQLPHP <pgsql-php@postgresql.org>
Subject: Re: See postgre tables from PHP code
Date: Wed, 12 Nov 2008 22:03:00 +1300
Message-ID: <1226480580.6868.246.camel@happy.mcmillan.net.nz> (raw)
In-Reply-To: <001501c942e9$665772b0$3000a8c0@atenea>
References: <001501c942e9$665772b0$3000a8c0@atenea>

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<space><tab><tab> 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.
------------------------------------------------------------------------





view thread (5+ messages)  latest in thread

Message-ID: <1226480580.6868.246.camel@happy.mcmillan.net.nz>
Permalink:  ../1226480580.6868.246.camel@happy.mcmillan.net.nz/
Also on:    postgresql.org/message-id/1226480580.6868.246.camel@happy.mcmillan.net.nz

 · 

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: andrew@morphoss.com, fesanch@ciego.cult.cu
  Subject: Re: See postgre tables from PHP code
  In-Reply-To: <1226480580.6868.246.camel@happy.mcmillan.net.nz>
  References: <001501c942e9$665772b0$3000a8c0@atenea> <1226480580.6868.246.camel@happy.mcmillan.net.nz>

* 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