I'm having a terribly difficult time getting the command "pg_connect()" to work properly on my Mac. I'm currently writing a PHP script (to be executed from console) to read a PostgreSQL database and email a report.
I've gone into my php.ini
file and added
extension=pgsql.so
But, I'm met with the following error.
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20090626/php_pgsql.so' - dlopen(/usr/lib/php/extensions/no-debug-non-zts-20090626/php_pgsql.so, 9): image not found in Unknown on line 0
PHP Fatal error: Call to undefined function pg_connect() in... (blah file here)
When running phpinfo()
, I see nothing about PostgreSQL, so what is my issue here?
PHP 5.4 or higher is required: 5.4, 5.5, 5.6, 7.0, ... You need to chose between, PostgeSQL PHP extension and PostgreSQL PDO extension. You need to activate the extension you chose.
PostgreSQL Functions (PDO_PGSQL) ¶PDO_PGSQL is a driver that implements the PHP Data Objects (PDO) interface to enable access from PHP to PostgreSQL databases.
The PHP version that comes bundled with OS X doesn't include PostgreSQL. You'll have to compile the extension yourself. Here are some instructions:
php -v
.curl -O http://us.php.net/distributions/php-5.3.3.tar.gz
. (This example downloads PHP 5.3.3 but this must match your version)tar -xzvf php-5.3.3.tar.gz
cd php-5.3.3/ext/pgsql/
phpize
../configure
.make
.sudo make install
.php.ini
file by adding extension=pgsql.so
. (You may already have done this)Update for OS X Mountain Lion Apple has removed autoconf
from the newer versions of XCode so the procedure above will fail at #5. To solve that problem:
/usr/bin/ruby -e "$(/usr/bin/curl -fksSL https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)"
.sudo chown -R $USER /usr/local/Cellar
.brew update
.brew install autoconf
.That should install autoconf
and allow you to install the module using the instructions above.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With