views:

110

answers:

5

Hi,

I was trying to connect my PHP page to PostgreSQL, but it's not working. The code which I have tried is given below:

<?php

 $connection = pg_connect("host=localhost dbname=mydb user=postgres password=pgsql"); 

 if (!$connection)
 { 
   echo "Couldn't make a connection!"; 
 } 

?>

During the time of installation, the system asked me for a password and I had gives as pgsql. My database name is "mydb". Somebody please help me.

Thanks and regards.

tismon

A: 

I advice you to take a look at pg_last_error, it would give you valuable info on what is going wrong

i.e.

if(!$connection){
 die(pg_last_error($connection));
}
RageZ
i didnt get any error message even it doesnot printing the other simple echo after the connection string :(
tismon
like pointed by max you should have something in apache log, if you have shell access to the server you can try to use `psql` and see if you can connect like expected.
RageZ
A: 

Maybe the pgsql module isn't installed/loaded?

<?php
echo "<pre>If this line isn't printed you have a parse error in your script</pre>\n"; flush();
error_reporting(E_ALL); ini_set('display_errors', true);    
extension_loaded('pgsql') || die('pgsql module unavailable');


$connection = pg_connect("host=localhost dbname=mydb user=postgres password=pgsql"); 
if (!$connection) { 
  echo "Couldn't make a connection! ". pg_last_error(); 
}
else {
  echo 'connected to server';
}
flush();
?>
VolkerK
A: 

Hi list, The error message i got after troubleshooting is

"pgsql module unavailable"

I set the

extension=php_pdo_pgsql.dll extension=php_pgsql.dll

and extension_dir = "C:\php\ext"

in the php.ini file.But it was of no use.

I use postgresql 8.3 and php 5.2.12 threadsafe with apache 2.2 in win xp...

any help will be deeply appreciated..

Tismon

tismon
A: 

Hi

i couldnt solve the above shown error.. somebody please help me..

when i was trying to connect with postgresql using pg_connect(), it says that "Fatal error.. call to undefined function pg_connect..".

please help me....

Thanks & regards

Tismon Varghese

tismon
A: 

Hi

its solved.. the problem is with the php version. i had installed php5.2.6 and replced the pgsql.dll extension with that of php5.2.5

Thanks a lot VolkerK,RageZ and Max S

regards

tismon

tismon