Thread: Postgres + PHP question: username in pg_connect?

Postgres + PHP question: username in pg_connect?

From
Erich
Date:
I'm getting ready to switch over from MySQL to Postgres for my PHP
application.  Looking over the docs of PHP, it shows a pg_connect
command, which doesn't accept a user name.  Any ideas on how to get it
to connect with a specified user name?  Or do I have to run apache as
a specific user, and have that user have a postgres user account?
Right now, apache is running as nobody, which is pretty normal for
apache.

Thanks,

e

Re: Postgres + PHP question: username in pg_connect?

From
"Brett W. McCoy"
Date:
On Tue, 18 Jul 2000, Erich wrote:

> I'm getting ready to switch over from MySQL to Postgres for my PHP
> application.  Looking over the docs of PHP, it shows a pg_connect
> command, which doesn't accept a user name.

Sure it does:

$conn = pg_connect("dbname=orders host=localhost user=orders_admin
password=ORDERS!admin");

This also applies to pg_pconnect, for persistent conenctions.

Brett W. McCoy
                                              http://www.chapelperilous.net
---------------------------------------------------------------------------
You can learn many things from children.  How much patience you have,
for instance.
        -- Franklin P. Jones


Re: Postgres + PHP question: username in pg_connect?

From
Andrew Sullivan
Date:
On Tue, Jul 18, 2000 at 04:51:09PM -0700, Erich wrote:
>
> I'm getting ready to switch over from MySQL to Postgres for my PHP
> application.  Looking over the docs of PHP, it shows a pg_connect
> command, which doesn't accept a user name.  Any ideas on how to get it
> to connect with a specified user name?  Or do I have to run apache as
> a specific user, and have that user have a postgres user account?
> Right now, apache is running as nobody, which is pretty normal for
> apache.

The docs are incomplete.  If you read the "annotated" version of the PHP
docs, you'll see that several people complain about this.  The way to connect
with a username is

$db = pg_Connect ("host=[somehost] port=[correct port]
    dbname=[your_database] user=[username] password=[password]");

(normally you'd do that as one line).  The options aren't all necessary, so
you don't need to use passwords if you don't want.

By the way, you'd be better off, in almost every circumsntance, to use
pg_pConnect.  Then, you don't have to open a new database connection every
time you want to do an operation.  The overhead of that really hurts.

--
Andrew Sullivan                                      Computer Services
<sullivana@bpl.on.ca>                        Burlington Public Library
+1 905 639 3611 x158                                   2331 New Street
                                   Burlington, Ontario, Canada L7R 1J4