Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fatal error: Call to undefined function pg_connect()

I am trying to connect to my database (remote server) which has PostgreSQL installed in it. My PHP code is trying to connect to the database using pg_connect(), but I get the error saying:- "Fatal error: Call to undefined function pg_connect() in /var/www/website/functions.php on line 82".

The line 82 simply is:

$db = pg_connect($conn_string);
where $conn_string = "host=".$hostname." port=5432 dbname=".$dbname." user=".$db_user." password=".$db_password.""

(all variables defined earlier)

I checked many forums and the only solution suggested was locating the php.ini file which contains a line:- extension = pgsql.so (for UNIX) and extension = php_pgsql.dll (for Windows).

This statement is supposed to be commented and the solution is to uncomment it. I have tried it but still does not change the situation. The remote server has a version later than PostgreSQL v9.0.4 installed. I then installed PostgreSQL v8.4.8 on to my laptop and ran the website locally using MAMP. At first, Apache crashed for some odd reason, I fixed that problem but again I ended up with the same error as before i.e. Fatal error: Call to undefined function pg_connect()....

I also ran the phpinfo() and it showed that the php version does support the PostgreSQL module.I have spent an entire day searching for the solution but have been unsuccessful. This is my first project developing a website and I am out of wits. Any kinda help will be highly appreciated.

phpinfo() gives me a huge list of things at the terminal but the listings relevant to PostgreSQL are as follows:-

pdo_pgsql

PDO Driver for PostgreSQL => enabled
PostgreSQL(libpq) Version => 9.0.4
Module version => 1.0.2
Revision =>  $Id: pdo_pgsql.c 306939 2011-01-01 02:19:59Z felipe $ 

pgsql

PostgreSQL Support => enabled
PostgreSQL(libpq) Version => 9.0.4
Multibyte character support => enabled
SSL support => enabled
Active Persistent Links => 0
Active Links => 0

Directive => Local Value => Master Value
pgsql.allow_persistent => On => On
pgsql.auto_reset_persistent => Off => Off
pgsql.ignore_notice => Off => Off
pgsql.log_notice => Off => Off
pgsql.max_links => Unlimited => Unlimited
pgsql.max_persistent => Unlimited => Unlimited

I had restarted MAMP after every edit I made since it was mentioned in every post I have read so far. I believe that resets both Apache and php.

'pqsql.so' (which is the UNIX equivalent of 'php_pqsql.dll' in Windows) is present in the 'extension' directory. I also copy-pasted the 'pqsql.so' file on to the Apache/bin directory but it did not give me any change.

I am not running php in the command line primarily. I just was curious to see what phpinfo() would give me relevant to pgsql which I have mentioned in my reply above.

I am still working on the tools you have mentioned and will respond as soon as I get any results.

Thanks, H

like image 359
hrshd Avatar asked Sep 15 '11 22:09

hrshd


2 Answers

You need to install the php-pgsql package or whatever it's called for your platform. Which I don't think you said by the way.

On Ubuntu and Debian:

sudo apt-get install php-pgsql
like image 97
Scott Marlowe Avatar answered Nov 11 '22 20:11

Scott Marlowe


Easy install for ubuntu:

Just run:

sudo apt-get install php5-pgsql

then

sudo service apache2 restart //restart apache

or

Uncomment the following in php.ini by removing the ;

;extension=php_pgsql.dll

then restart apache

like image 20
Angelin Nadar Avatar answered Nov 11 '22 21:11

Angelin Nadar