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 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。