在Mac OS X上的PHP中启用PostgreSQL支持 [英] Enabling PostgreSQL support in PHP on Mac OS X

查看:258
本文介绍了在Mac OS X上的PHP中启用PostgreSQL支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难在Mac上正常使用命令"pg_connect()".我目前正在编写一个PHP脚本(将从控制台执行)以读取PostgreSQL数据库并通过电子邮件发送报告.

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.

我进入了php.ini文件并添加了

extension=pgsql.so

但是,我遇到以下错误.

But, I'm met with the following error.

PHP警告:PHP启动:无法加载动态库'/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):在第0行的未知"中找不到图像
PHP致命错误:在...(此处为空白文件)中调用未定义的函数pg_connect()

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)

运行phpinfo()时,我对PostgreSQL没有任何了解,所以这里的问题是什么?

When running phpinfo(), I see nothing about PostgreSQL, so what is my issue here?

推荐答案

OS X附带的PHP版本不包含PostgreSQL.您必须自己编译扩展.以下是一些说明:

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:

  1. 找到您的PHP版本:php -v.
  2. 下载与您相匹配的PHP版本:curl -O http://us.php.net/distributions/php-5.3.3.tar.gz. (此示例下载了PHP 5.3.3,但这必须与您的版本匹配)
  3. 解压缩下载的档案:tar -xzvf php-5.3.3.tar.gz
  4. 更改为PostgreSQL的扩展目录:cd php-5.3.3/ext/pgsql/
  5. 键入phpize.
  6. 键入./configure.
  7. 键入make.
  8. 键入sudo make install.
  9. 通过添加extension=pgsql.so将扩展名添加到您的php.ini文件中. (您可能已经这样做了)
  10. 重新启动Apache.
  1. Find your version of PHP: php -v.
  2. Download the version of PHP that matches yours: 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)
  3. Extract the archive you downloaded: tar -xzvf php-5.3.3.tar.gz
  4. Change to the PostgreSQL's extension directory: cd php-5.3.3/ext/pgsql/
  5. Type phpize.
  6. Type ./configure.
  7. Type make.
  8. Type sudo make install.
  9. Add the extension to you php.ini file by adding extension=pgsql.so. (You may already have done this)
  10. Restart Apache.

针对OS X Mountain Lion的更新 Apple已从较新版本的XCode中删除了autoconf,因此上述过程将在#5处失败.要解决该问题:

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:

  1. 键入/usr/bin/ruby -e "$(/usr/bin/curl -fksSL https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)".
  2. 键入sudo chown -R $USER /usr/local/Cellar.
  3. 键入brew update.
  4. 键入brew install autoconf.
  1. Type /usr/bin/ruby -e "$(/usr/bin/curl -fksSL https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)".
  2. Type sudo chown -R $USER /usr/local/Cellar.
  3. Type brew update.
  4. Type brew install autoconf.

这应该安装autoconf,并允许您按照上述说明安装模块.

That should install autoconf and allow you to install the module using the instructions above.

这篇关于在Mac OS X上的PHP中启用PostgreSQL支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆