macdo x yosemite上的pdo_pgsql和php

时间:2015-06-04 16:13:20

标签: php osx-yosemite

所以我从源代码编译了pdo_pgsql并将扩展名添加到我的php.ini

phpinfo()

PDO

PDO support enabled
PDO drivers mysql, sqlite, pgsql

pdo_pgsql

PDO Driver for PostgreSQL   enabled
PostgreSQL(libpq) Version   9.4.2
Module version  1.0.2

pg_connect("host=localhost dbname=dbname user=username password=password")

给出

Call to undefined function pg_connect()

是的,我确实重启了apache。

SERVER_SOFTWARE Apache/2.4.10 (Unix) PHP/5.5.20

我使用的是Mac OS X Yosemite 10.10.3

谢谢!

1 个答案:

答案 0 :(得分:2)

如何使你的连接如此:

    try {
        $conn = new PDO('pgsql:host=localhost;port=port-number;dbname=database','db-user','db-pass');

        $conn->query("SET NAMES UTF8");
    } catch (PDOException $e) {
        die('Connection failed: ' . $e->getMessage());
    }