connecting to postgress in php

  • gibby
  • Newbie
  • Newbie
  • gibby
  • Posts: 5

Post 3+ Months Ago

I'm trying to connect to a postgres database using the code below but it doesn't seem to work.

echo 'point 0<br>';
$con = pg_Connect("dbname=testdb port=5432 user=postgres");
if ($con == 0) {
die ("Could not connect");
echo 'point 1<br>';

and all that shows up in my web browser is

point 0

Shoudn't it at least be telling me that it 'Could not connect'? What does this mean?

I've got my database in usr/local/pgsql/data, my username is 'postgres' and I don't have a password, and I'm running my php file out of localhost (usr/local/apache2/htdocs). help!

  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Posts: 3423
  • Loc: Richland, WA

Post 3+ Months Ago

well hmm eer not sure if this matters but the echo statment is
echo "stuff";

not sure if ' works
but im a noob so

>< cross that out, is point 0 a varible?
cuse if it is you need the $ and there cant be any spaces
  • steve101
  • Beginner
  • Beginner
  • steve101
  • Posts: 35

Post 3+ Months Ago

well i'm not exactly sure what your plan is, but if you want to display 'point 1' if the connection is successful you could try this? The php functions usually have to be lowercase...

PHP Code: [ Select ]
echo 'point 0
$con = pg_connect("dbname=testdb port=5432 user=postgres");
if(!$con) {
die("Could not connect");
} else {
echo 'point 1
'; }
  1. <?php
  3. echo 'point 0
  5. ';
  7. $con = pg_connect("dbname=testdb port=5432 user=postgres");
  9. if(!$con) {
  11. die("Could not connect");
  13. } else {
  15. echo 'point 1
  17. '; }
  19. ?>

  • gibby
  • Newbie
  • Newbie
  • gibby
  • Posts: 5

Post 3+ Months Ago

OK, I got display_errors working and it's telling me

Fatal error: Call to undefined function: pg_connect() in /usr/local...

So it looks like support for pgsql was not installed, but I'm sure I configured php with

./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-pgsql

According to ./configure --help, if the DIR path in '--with-pgsql[=DIR]' is left blank (which it was), it will default to /usr/local/pgsql which shouldn't be a problem, right?

Some things I noticed when I called phpinfo() were as follows:
-disable_functions = no value
-Hostname:port = localhost.localdomain:0
-Loaded Modules DO NOT include mod_pgsql or anything of the sort.
-Supported databases, however, DO support PostgreSQL.
-remote_port: 1024

Also, I checked out pg_hba.conf and everything seems to be set to 'ALL' (including databases).

What reason could there be for pg_connect() not being recognized?


Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 24 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum

© 1998-2017. Ozzu® is a registered trademark of Unmelted, LLC.