[SOLVED] Trying to test PHP connectivity to Postgresql 8.3.9 (CentOS 5.5 x86_64)
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
Trying to test PHP connectivity to Postgresql 8.3.9 (CentOS 5.5 x86_64)
hello. I'm learning via baptism by fire method here, and need to test PHP connectivity to a local postgresql 8.3.9 setup. I have got PHP and Postgres both working; I can pull up a test PHP page via web browser, and I can login to postgres via the command line.
What I can't figure out is how to test PHP connectivity to the local DB.
I found this test script:
$conn = pg_connect ('dbname=template1');
which I've named, testdb.php - when I run ./testdb.php from the CLI though, I get:
./testdb.php: line 2: ?php: No such file or directory
./testdb.php: line 3: syntax error near unexpected token `"dbname=template1"'
./testdb.php: line 3: `$database=pg_connect ("dbname=template1");'
I've seen a LOT of pages describing the internal code of the PHP file, but as a newb to this, I don't know how to execute this test.
advice please? ive ran chmod 755 against the file to verify permissions, but this didnt effect the results. I've also done a "chmod +x testdb.php"
PHP 5.1.6 (cli) (built: Mar 31 2010 02:39:17)
[EDIT]: OK. DUH. I realized I wasn't doing this:
but when I do, I get this error message now:
"PHP Fatal error: Call to undefined function pg_connect() in /var/www/html/testdb.php on line 3"
hey thanks for the quick reply. I was editing my post when you were replying, as I realized I had forgot to run what you said, both the "php testdb.php" and then making the file executable, via "chmod +x"
please see the PHP Fatal error though. I haven't had a chance to google this yet. my apologies if it shows up as 1st entry
I've gotten a step closer. I didnt have php-pgsql.x86_64 installed. YUM'd that, restart HTTPD, now I'm getting an auth error for root. getting closer.
I believe for cli php usage, you should be using "php -f testdb.php". for some reason i have had many troubles with shebangs when using php.
Also, for MySQL you need to supply more than just the DB name. Probably the same with Postgress
$con = mysql_connect(127.0.0.1, USER, PASSWORD) OR die('Couldn\'t access database server');
mysql_select_db(testdb) OR die('Couldn\'t access database');
i can login via CLI to the 'test' database with the 'jw' user without any issues - but I receive this when executing 'php testdb.php':
PHP Warning: pg_connect(): Unable to connect to PostgreSQL server: FATAL: Ident authentication failed
then I found online that I should inspect pg_hba.conf - so I did. I wound up relaxing the security so I can just verify this test (the test is to actually show that PHP, mod_perl, postgres and apache can live and work harmoniously together in a monolithic binary install)
local all all trust
host all all 0.0.0.0 0.0.0.0 trust
Now, once I did this, I get no errors when I execute: 'php testdb.php' - I echoed the return status and got a "0", but the postgresql-x-x-x_x.log doesn't really validate that I successfully connected to the 'test' db w/ the 'jw' user account. Is there another quick way to verify this?
I suppose I could add tables, data, and then plug in a query to return the # of rows, etc.. I'm just really trying to do a simple connectivity test and if I've succeeded, then I'm happy.
Thanks so much for anyone's patience who is viewing and replying to this.
I went back and ran ALTER USER postgres with password 'test'; to just verify that I had the right password, and I get the same results. I can login to pgsql from the command line, but cannot run this testdb.php script
any reason pg_hba.conf was not found loaded in this setup? meaning, only the pg_hba.conf.sample file was found.
local all all trust
host all all 0.0.0.0 0.0.0.0 trust
to pg_hba.conf, restarted postgresql, and the "php testdb.php" didnt return any errors.
im just curious, why when i ran "locate pg_hba.conf" it returned nothing.
anyways. thanks for your help.
p.s. - anyway you can take a look at the other thread I posted re: testing connectivity b/t mod_perl > mysql. I'm super confused on how to conduct that. seems like i get the wrong search terms in google, and once i get the query right, the answer pops out, but I cant seem to tease the answer(s) i need out of my searches so far.