Thread: PostgreSQL connect error
Hi Friends,
I wrote a sample php program that connects to PostgreSQL DB.
==> I was able to run the PHP program from the command prompt as postgres user & not as anyother user
$ php pgsql.php
==> I was not able execute the same file from the web browser. FATAL ERROR- undefined function pg_connect().
How to resolve this issue? Please help.
Thanks
DEVI.G
devi wrote: > Hi Friends, > > I wrote a sample php program that connects to PostgreSQL DB. > > ==> I was able to run the PHP program from the command prompt as > postgres user & not as anyother user > $ php pgsql.php > > ==> I was not able execute the same file from the web browser. FATAL > ERROR- undefined function pg_connect(). > > How to resolve this issue? Please help. wild guess says, compare your PATH and other key environment variables (such as LD_LIBRARY_PATH) while logged in as postgres vs your other user... adjust the path of this other user to suit.
devi schrieb: > Hi Friends, > > I wrote a sample php program that connects to PostgreSQL DB. > > ==> I was able to run the PHP program from the command prompt as > postgres user & not as anyother user > $ php pgsql.php > > ==> I was not able execute the same file from the web browser. FATAL > ERROR- undefined function pg_connect(). > > How to resolve this issue? Please help. > > Thanks > DEVI.G Apparently your php CLI binary has support for PostgreSQL compiled in, your web server not. Resolving this highly depends on your platform; it might be as easy as installing an RPM and restarting the web server, or you needing to recompile PHP with PostgreSQL support compiled in. Ciao, Thomas
Hi , As john suggested, i tried setting up the env .. but that dosen't help out. I tried with IP, instead of localhost in pg_hba.conf.. just trail & error approach... Now.. i'm getting the error as "FATAL: role "apache" does not exist..".. Can U help me out here!! Thanks DEVI.G ----- Original Message ----- From: "Thomas Pundt" <mlists@rp-online.de> To: "devi" <devi@visolve.com>; <pgsql-general@postgresql.org> Sent: Tuesday, March 10, 2009 2:53 PM Subject: Re: [GENERAL] PostgreSQL connect error > devi schrieb: >> Hi Friends, >> I wrote a sample php program that connects to PostgreSQL DB. >> ==> I was able to run the PHP program from the command prompt as >> postgres user & not as anyother user >> $ php pgsql.php >> ==> I was not able execute the same file from the web browser. FATAL >> ERROR- undefined function pg_connect(). >> How to resolve this issue? Please help. >> Thanks >> DEVI.G > > Apparently your php CLI binary has support for PostgreSQL compiled in, > your web server not. Resolving this highly depends on your platform; > it might be as easy as installing an RPM and restarting the web server, > or you needing to recompile PHP with PostgreSQL support compiled in. > > Ciao, > Thomas > > -- > Sent via pgsql-general mailing list (pgsql-general@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-general >
devi wrote: > Hi , > > As john suggested, i tried setting up the env .. but that dosen't help > out. I tried with IP, instead of localhost in pg_hba.conf.. just trail & > error approach... There is no need to use trial and error - this is covered in the manuals: http://www.postgresql.org/docs/current/static/client-authentication.html > Now.. i'm getting the error as "FATAL: role "apache" does not exist..".. > > Can U help me out here!! You're trying to connect with a username of "apache" and you don't have that set up in the database. Stop. Make a good hot cup of tea/coffee and read through the section of the manual mentioned above. Disable access from the internet (listen_addresses) and set up "trust" access as a first step. Connect as the postgres user (from psql), add a new database user (e.g. "test") with a password (see the manuals for details). Create a database owned by them. Now try logging in as that user - no password should be necessary. Edit the pg_hba.conf to require passwords for all users apart from "postgres" which you can leave as "ident". Restart the postgresql server and try reconnecting as your test user. You should now need a password. If all that's working, try connecting as your test user from php. Don't forget to check result codes when you connect to the database or send a query etc. -- Richard Huxton Archonet Ltd
Hi Richard, Thanks & it works.. DEVI.G ----- Original Message ----- From: "Richard Huxton" <dev@archonet.com> To: "devi" <devi@visolve.com> Cc: <thomas.pundt@rp-online.de>; <pgsql-general@postgresql.org> Sent: Tuesday, March 10, 2009 3:39 PM Subject: Re: [GENERAL] PostgreSQL connect error > devi wrote: >> Hi , >> >> As john suggested, i tried setting up the env .. but that dosen't help >> out. I tried with IP, instead of localhost in pg_hba.conf.. just trail & >> error approach... > > There is no need to use trial and error - this is covered in the manuals: > http://www.postgresql.org/docs/current/static/client-authentication.html > >> Now.. i'm getting the error as "FATAL: role "apache" does not exist..".. >> >> Can U help me out here!! > > You're trying to connect with a username of "apache" and you don't have > that set up in the database. > > Stop. Make a good hot cup of tea/coffee and read through the section of > the manual mentioned above. Disable access from the internet > (listen_addresses) and set up "trust" access as a first step. > > Connect as the postgres user (from psql), add a new database user (e.g. > "test") with a password (see the manuals for details). Create a database > owned by them. Now try logging in as that user - no password should be > necessary. > > Edit the pg_hba.conf to require passwords for all users apart from > "postgres" which you can leave as "ident". Restart the postgresql server > and try reconnecting as your test user. You should now need a password. > > If all that's working, try connecting as your test user from php. Don't > forget to check result codes when you connect to the database or send a > query etc. > > -- > Richard Huxton > Archonet Ltd > > -- > Sent via pgsql-general mailing list (pgsql-general@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-general >