View Full Version : PHP + Postgres Problem

December 10th, 2005, 06:57 PM
I'm trying to use postgres database in my php application, but I get an error on the first command - pg_connect(). Is there anyone, who installed it and have it working, and could help me with it? The dbms, apache and php works fine, I simply cannot to the database via php.

December 10th, 2005, 09:12 PM
What is the exact error?

December 10th, 2005, 09:46 PM
Fatal error: Call to undefined function: pg_connect() in /var/www/usos/logowanie.php on line 7

And the php code:

$database = pg_connect("dbname=usos");

I have some question too - do I have to be logged to the database, while trying to reach it via php?

In /etc/php4/apache2/php.ini I added this line


Any idea, what might be wrong?

December 10th, 2005, 09:50 PM
Do you have the php-pgsql package installed?

December 10th, 2005, 10:00 PM
I did everything as it is written here https://wiki.ubuntu.com/ApacheMySQLPHP , except for the fact, that I didn't isnstall mySQL. Therefore I assume, that I didn't install php-pgsql package. How should I do it?
sudo apt-get install php-pgsql is enough?

December 10th, 2005, 10:02 PM
sudo apt-get install php4-pgsql
or replace 4 with 5, if that is what you are using.

Be sure to restart apache after you get it installed.

December 10th, 2005, 10:27 PM
OK, i'll try it. Thank you very much, I really appreciate your help.

I found what caused the error. Now everything works fine. Once again: thanks.

February 22nd, 2006, 05:05 AM
What was the solution to your problem?
I am having the same problem...


March 2nd, 2006, 02:43 AM
Yes, installing the php5-pgsql package solves the problem.
apt-get install php5-pgsqlAs stated, be sure to restart Apache.
/etc/init.d/apache2 restart