开发者

connect PHP with postgreSQL8.3

开发者 https://www.devze.com 2022-12-19 17:43 出处:网络
I was trying to connect my PHP page to PostgreSQL, but it\'s not working. The code which I have tried is given below:

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 =开发者_Python百科 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


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));
}


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


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


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();
?>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号