0

When I try to execute pg_connect() in PHP, it does not work and I have come to the realization that my php settings are such that it cannot understand this function, and the php error message reads:

Fatal error: "Call to undefined function pg_connect() in test.php on line 11"

I have downloaded postgresql with yum install postgresql-server in terminal, but nothing more than that.

I have heard from other sources online that I should edit a configuration file, but I don't know where it is.

3 Answers 3

2

Make sure you have extension=php_pgsql.dll in your php.ini.

Also, enabling extension=php_pdo_pgsql.dll would be a good idea too in case you decide to use a PDO in the future.

Sign up to request clarification or add additional context in comments.

4 Comments

Hi! Just did as told, and now I receive a php Warning: "Warning: Unable to load dynamic library '/usr/lib/php/modules/php_pgsql.dll' - /usr/lib/php/modules/php_pgsql.dll: cannot open shared object file: No such file or directory in Unknown on line 0"
In fact I looked in this directory and neither of those files were there.
If you're using linux the extension will be different (.so). These packages are packaged with PHP by default so they usually appear in your php.ini already, just with a leading ;. If you're on linux and you're still missing the extension you can run apt-get install php5-pgsql.
I am indeed in linux, however when I tried to execute that command, however I get the error "bash: apt-get: command not found"
2

Others have pointed out that you must edit php.ini. That's right for some installs, but only helps if the PostgreSQL interface for PHP is actually present.

On Fedora, that's the php-pgsql package:

yum install php-pgsql

This package will add a file to /etc/php.d/ which is a directory of php.ini snippets.

Just editing php.ini without installing the correct package won't help you, and if you install the package you don't need to edit php.ini.

In any case, please just use PDO. The PostgreSQL extension for PHP isn't well maintained these days, and the strong push toward PDO is likely to make your life harder over time.

Comments

0

Enable php_pgsql in your server. Click on your WAMP (if its WAMP server)->PHP->PHP extensions->php_pgsql (click on it).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.