dourang8305 2016-07-26 10:05
浏览 52

pg_connect()与osx的undefined-error

i'm getting the following error while trying to run PostgreSQL with PHP & Apache on OS X El Capitan:

Fatal error: Call to undefined function pg_connect()

I have setup Apache & PHP recently and wanted now to add PostgreSQL for database queries. Postgres.app worked well with Java so far. I'm afraid that I miss some very trivial configuration detail.

PHP worked well with php version 5.5.34, so I just wanted to run:

brew install php55-pdo-pgsql

I adjusted the apache-config and recognized brew installed php 5.5.38, as phpinfo(); now shows 38 instead of 34.

Typing php -v in terminal still gives me 5.5.34.

I also tried to do:

brew install php56-pdo-pgsql

But pg_connect() is still undefined. phpinfo(); returns then:

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 $
  • 写回答

2条回答 默认 最新

  • dqde43215 2016-07-28 06:36
    关注

    For anybody having the same problem, simply run:

    brew install php56 --with-postgresql
    

    instead of just

    brew install php56
    

    This sets up php with both pgsql and pdo-pgsql module. In my case the pgsql module was missing.

    I did:

    brew install php56
    brew install php56-pdo-pgsql
    

    which seems to install php with only pdo-pgsql and not the pgsql module

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

    After all that I started postgresql and used psql:

    brew services start postgresql
    psql postgres
    

    The standard superuser was like my login-name for the mac (maybe not as usually postgres), but once connected to psql you can create your own.

    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)