【问题标题】:pg_connect() undefined-error with osxpg_connect() undefined-error with osx
【发布时间】:2016-07-26 10:05:56
【问题描述】:

我在 OS X El Capitan 上尝试使用 PHP 和 Apache 运行 PostgreSQL 时遇到以下错误:

致命错误:调用未定义函数 pg_connect()

我最近设置了 Apache 和 PHP,现在想为数据库查询添加 PostgreSQL。到目前为止,Postgres.app 与 Java 配合得很好。恐怕我会错过一些非常琐碎的配置细节。

PHP 在 php 版本 5.5.34 上运行良好,所以我只想运行:

brew install php55-pdo-pgsql

我调整了 apache-config 并识别 brew 安装的 php 5.5.38,为 phpinfo();现在显示 38 而不是 34。

在终端中键入 php -v 仍然给我 5.5.34。

我也尝试过:

brew install php56-pdo-pgsql

但是 pg_connect() 仍然是未定义的。 phpinfo();然后返回:

PHP Version 5.6.24 System   Darwin XXXYYYZZZ 15.5.0 Darwin Kernel Version 15.5.0: Tue Apr 19 18:36:36 PDT 2016; root:xnu-3248.50.21~8/RELEASE_X86_64 x86_64
    Build Date  Jul 22 2016 02:40:35
    Configure Command   './configure' '--prefix=/usr/local/Cellar/php56/5.6.24' '--localstatedir=/usr/local/var' '--sysconfdir=/usr/local/etc/php/5.6' '--with-config-file-path=/usr/local/etc/php/5.6' '--with-config-file-scan-dir=/usr/local/etc/php/5.6/conf.d' '--mandir=/usr/local/Cellar/php56/5.6.24/share/man' '--enable-bcmath' '--enable-calendar' '--enable-dba' '--enable-exif' '--enable-ftp' '--enable-gd-native-ttf' '--enable-mbregex' '--enable-mbstring' '--enable-shmop' '--enable-soap' '--enable-sockets' 
'--enable-sysvmsg' '--enable-sysvsem' '--enable-sysvshm' '--enable-wddx' '--enable-zip' '--with-freetype-dir=/usr/local/opt/freetype' '--with-gd' '--with-gettext=/usr/local/opt/gettext' '--with-iconv-dir=/usr' '--with-icu-dir=/usr/local/opt/icu4c' '--with-jpeg-dir=/usr/local/opt/jpeg' '--with-kerberos=/usr' '--with-libedit' '--with-mhash' '--with-ndbm=/usr' '--with-png-dir=/usr/local/opt/libpng' '--with-xmlrpc' '--with-zlib=/usr' '--with-readline=/usr/local/opt/readline' '--without-gmp' '--without-snmp' 
'--with-libxml-dir=/usr/local/opt/libxml2' '--with-pdo-odbc=unixODBC,/usr/local/opt/unixodbc' '--with-unixODBC=/usr/local/opt/unixodbc' '--with-apxs2=/usr/sbin/apxs' '--libexecdir=/usr/local/Cellar/php56/5.6.24/libexec' '--with-bz2=/usr' '--disable-debug' '--with-openssl=/usr/local/opt/openssl' '--enable-fpm' '--with-fpm-user=_www' '--with-fpm-group=_www' '--with-curl' '--with-xsl=/usr' '--with-ldap' '--with-ldap-sasl=/usr' '--with-mysql-sock=/tmp/mysql.sock' '--with-mysqli=mysqlnd' '--with-mysql=mysqlnd' 
'--with-pdo-mysql=mysqlnd' '--disable-opcache' '--enable-pcntl' '--without-pear' '--enable-dtrace' '--disable-phpdbg' '--enable-zend-signals' 'CC=clang' 'CXX=clang++'

[...]

pdo_pgsql

PDO Driver for PostgreSQL   enabled
PostgreSQL(libpq) Version   9.5.3
Module version  1.0.2
Revision    $Id: 0e858dd2051ca8c2fd3c781909a0670ab5fecd36 $

【问题讨论】:

  • 您是如何获得/安装 php 的?我没有看到在哪里启用了 postgresql。
  • 我已经安装了 5.5.34 版本并按照指南让 apache 服务器运行 php。对于更高版本:它不是使用 brew install 命令安装的,因为它是一个依赖项?
  • 关于 postgresql:brew install postgresql 说已经安装了 9.5.3

标签: php macos postgresql homebrew


【解决方案1】:

对于遇到相同问题的任何人,只需运行:

brew install php56 --with-postgresql

而不仅仅是

brew install php56

这将设置 php 与 pgsql 和 pdo-pgsql 模块。在我的情况下,pgsql 模块丢失了。

我做到了:

brew install php56
brew install php56-pdo-pgsql

这似乎只安装了 pdo-pgsql 而不是 pgsql 模块的 php

见:https://serverfault.com/questions/533103/how-to-add-postgres-support-to-php-installed-by-homebrew

毕竟我启动了 postgresql 并使用了 psql:

brew services start postgresql
psql postgres

标准超级用户就像我的 mac 登录名(可能不像通常的 postgres),但一旦连接到 psql,您就可以创建自己的。

【讨论】:

    【解决方案2】:

    对于php7,现在也改为--with-postgresql

    Warning: homebrew/php/php71: --with-pgsql was deprecated; using --with-postgresql instead!
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-09-17
      • 1970-01-01
      • 2019-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多