Whirlwind
Whirlwind

Reputation: 13665

Call to undefined function pg_connect()

I am running the latest version of PHP (currently 5.6.22) on OSX El Capitan and Apache server.

I am trying to use PostgreSQL database and actually, yesterday already worked but after I haver overridden httpd.conf file with a default one (I guess this is the problem) I got this message:

Call to undefined function pg_connect() in ...

The thing is that I haven't changed php.ini file. If I run phpinfo(); I get etc/php.ini for a Configuration File. So I am positive that Apache choose the right php.ini file and that correct extensions are loaded:

extension=php_pdo_pgsql.dll
extension=php_pdo_sqlite.dll

What can cause this error ? Also I have installed pgAdmin 3 and I can successfully run SQL queries on created database (which I have used yesterday for this site I am working on).

EDIT:

This is what I get in error_log file when I restart Apache server and try to run that specific page (which calls pg_connect):

[Thu Jun 02 15:28:15.595496 2016] [mpm_prefork:notice] [pid 476] AH00169: caught SIGTERM, shutting down [Thu Jun 02 15:28:16.515774 2016] [so:warn] [pid 670] AH01574: module php5_module is already loaded, skipping PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20121212/php_curl.dll' - dlopen(/usr/lib/php/extensions/no-debug-non-zts-20121212/php_curl.dll, 9): image not found in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20121212/php_mbstring.dll' - dlopen(/usr/lib/php/extensions/no-debug-non-zts-20121212/php_mbstring.dll, 9): image not found in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20121212/php_mysqli.dll' - dlopen(/usr/lib/php/extensions/no-debug-non-zts-20121212/php_mysqli.dll, 9): image not found in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20121212/php_pdo_pgsql.dll' - dlopen(/usr/lib/php/extensions/no-debug-non-zts-20121212/php_pdo_pgsql.dll, 9): image not found in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20121212/php_pdo_sqlite.dll' - dlopen(/usr/lib/php/extensions/no-debug-non-zts-20121212/php_pdo_sqlite.dll, 9): image not found in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20121212/php_pgsql.dll' - dlopen(/usr/lib/php/extensions/no-debug-non-zts-20121212/php_pgsql.dll, 9): image not found in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20121212/php_soap.dll' - dlopen(/usr/lib/php/extensions/no-debug-non-zts-20121212/php_soap.dll, 9): image not found in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20121212/php_sockets.dll' - dlopen(/usr/lib/php/extensions/no-debug-non-zts-20121212/php_sockets.dll, 9): image not found in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20121212/php_sqlite3.dll' - dlopen(/usr/lib/php/extensions/no-debug-non-zts-20121212/php_sqlite3.dll, 9): image not found in Unknown on line 0 [Thu Jun 02 15:28:16.615703 2016] [mpm_prefork:notice] [pid 670] AH00163: Apache/2.4.18 (Unix) PHP/5.5.31 configured -- resuming normal operations [Thu Jun 02 15:28:16.615786 2016] [core:notice] [pid 670] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND' [Thu Jun 02 15:28:20.869683 2016] [:error] [pid 674] [client 127.0.0.1:49594] PHP Fatal error: Call to undefined function pg_connect() in /Library/WebServer/Documents/site/database.php on line 10

Upvotes: 1

Views: 8712

Answers (1)

CarlosCarucce
CarlosCarucce

Reputation: 3569

This happens when your pgsql extension is not installed or is not compatible with your current server build (x86/x64).

  1. Check if you have the correct file in you ext folder: php_pgsql.so (or php_pgsql.dll if youre running on windows)

  2. Search for the line extension=php_pdo_pgsql.dll in your php.ini. Then just add it if not found or remove the comma if its commented

  3. Run phpinfo() and check if the extension is enabled

If you found it, its good to go

Upvotes: 0

Related Questions