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

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

问题描述

我很难让命令pg_connect()"在我的 Mac 上正常工作.我目前正在编写一个 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 文件并添加了

I've gone into my php.ini file and added

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 行的 Unknown 中找不到图像
PHP 致命错误:调用未定义的函数 pg_connect() in...(此处为废话文件)

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.

那应该安装 autoconf 并允许您使用上述说明安装模块.

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

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

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