Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 更新到macOS Big Sur后,我可以';t使用MAMP连接到我的PostgreSQL数据库 代码_Php_Postgresql_Pdo_Mamp_Macos Big Sur - Fatal编程技术网

Php 更新到macOS Big Sur后,我可以';t使用MAMP连接到我的PostgreSQL数据库 代码

Php 更新到macOS Big Sur后,我可以';t使用MAMP连接到我的PostgreSQL数据库 代码,php,postgresql,pdo,mamp,macos-big-sur,Php,Postgresql,Pdo,Mamp,Macos Big Sur,下面是引发错误的代码 try { $myPDO = new PDO('pgsql:host=127.0.0.1:5432;dbname=test', 'test', ''); } catch (\Throwable $th) { echo var_dump($th); } 错误 这是我从“尝试/捕获”中得到的回应 object(PDOException)#2 (8) { ["message":protected]=> string(21) "

下面是引发错误的代码

try {
  $myPDO = new PDO('pgsql:host=127.0.0.1:5432;dbname=test', 'test', '');
} catch (\Throwable $th) {
  echo var_dump($th);
}
错误 这是我从“尝试/捕获”中得到的回应

object(PDOException)#2 (8) {
  ["message":protected]=>
  string(21) "could not find driver"
  ["string":"Exception":private]=>
  string(0) ""
  ["code":protected]=>
  int(0)
  ["file":protected]=>
  string(58) "/Users/test/index.php"
  ["line":protected]=>
  int(8)
  ["trace":"Exception":private]=>
  array(1) {
    [0]=>
    array(6) {
      ["file"]=>
      string(58) "/Users/test/index.php"
      ["line"]=>
      int(8)
      ["function"]=>
      string(11) "__construct"
      ["class"]=>
      string(3) "PDO"
      ["type"]=>
      string(2) "->"
      ["args"]=>
      array(3) {
        [0]=>
        string(46) "pgsql:host=127.0.0.1:5432;dbname=test"
        [1]=>
        string(13) "test"
        [2]=>
        string(0) ""
      }
    }
  }
  ["previous":"Exception":private]=>
  NULL
  ["errorInfo"]=>
  NULL
}
版本 我正在使用的软件版本列表

操作系统:南大苹果操作系统

MAMP:6.2

PHP:7.3.21


更新-更多上下文 在
php.ini
文件中,以下行未注释。根据php信息,这是正确的
php.ini
文件

extension_dir = "/Applications/MAMP/bin/php/php7.4.9/lib/php/extensions/no-debug-non-zts-20190902/"
...
extension=pgsql.so
extension=pdo_pgsql.so

Big Sur上的默认PHP安装不包括所需的PostgreSQL驱动程序。我通过安装了PHP7.4,其中包含以下驱动程序:

brew install php@7.4
确保这是默认的PHP版本。我正在使用,因此我需要运行此:

echo 'export PATH="/usr/local/opt/php@7.4/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/usr/local/opt/php@7.4/sbin:$PATH"' >> ~/.zshrc

您可以在这里找到php.ini(如果需要迁移配置):/usr/local/etc/php/7.4/php.ini

它正在运行吗?您需要检查Postgres服务器进程是否处于活动状态,但MAMP仍在运行。是的,Postgres正在运行。Postgres是在本地运行的,虽然与MAMP是分开的。但是可能,在我更新到Big Sur之后,我确实更新了MAMP(从5.x到6.2),希望这可能是我的问题。不过我会试试这个。也有同样的问题。我正在使用Symfony并使用其CLI启动本地服务器。因此,我不认为这是由MAMP堆栈引起的。博士后本身运作良好。我可以使用Postco连接到数据库,没有任何问题。我也可以使用Symfony服务器连接到数据库,太棒了-谢谢你的提示!我会试试这个,让你知道它是怎么回事。谢谢你帮了我。如果要立即使用相同的shell,请记住
source~/.zshrc