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.

<?php
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!

Gibran
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

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

Post 3+ Months Ago

well hmm eer not sure if this matters but the echo statment is
echo("stuff");
or
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 ]
<?php
 
echo 'point 0
 
';
 
$con = pg_connect("dbname=testdb port=5432 user=postgres");
 
if(!$con) {
 
die("Could not connect");
 
} else {
 
echo 'point 1
 
'; }
 
?>
  1. <?php
  2.  
  3. echo 'point 0
  4.  
  5. ';
  6.  
  7. $con = pg_connect("dbname=testdb port=5432 user=postgres");
  8.  
  9. if(!$con) {
  10.  
  11. die("Could not connect");
  12.  
  13. } else {
  14.  
  15. echo 'point 1
  16.  
  17. '; }
  18.  
  19. ?>


Steve
  • 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?

Gibran

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: hFJyCxL1 and 109 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-2014. Ozzu® is a registered trademark of Unmelted, LLC.