简体   繁体   English

更新到 macOS Big Sur 后,我无法使用 MAMP 连接到我的 PostgreSQL 数据库

[英]After updating to macOS Big Sur I can't connect to my PostgreSQL database with MAMP

Code代码

Here's the code that is throwing the error.这是引发错误的代码。

try {
  $myPDO = new PDO('pgsql:host=127.0.0.1:5432;dbname=test', 'test', '');
} catch (\Throwable $th) {
  echo var_dump($th);
}

Error错误

Here's the response I'm getting back from the try/catch.这是我从 try/catch 中得到的响应。

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
}

Versions版本

A list of the software versions I'm using.我正在使用的软件版本列表。

OS : macOS Big Sur操作系统:macOS 大苏尔

MAMP : 6.2 MAMP : 6.2

PHP : 7.3.21 PHP :7.3.21


Update - More Context更新 - 更多上下文

In the php.ini file the following lines are uncommented.php.ini文件中,以下行未注释。 This is the correct php.ini file according to PHP Info.根据 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

The default PHP installation on Big Sur doesn't include the required PostgreSQL driver. Big Sur 上的默认 PHP 安装不包括所需的 PostgreSQL 驱动程序。 I installed PHP 7.4 via Homebrew that does include this driver:我通过包含此驱动程序的Homebrew安装了 PHP 7.4:

brew install php@7.4

Make sure to make this the default PHP version.确保将其设为默认 PHP 版本。 I'm using Oh My Zsh so I need to run this:我正在使用Oh My Zsh ,所以我需要运行它:

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

You can find php.ini (in case you need to migrate configuration) here: /usr/local/etc/php/7.4/php.ini您可以在此处找到php.ini (以防您需要迁移配置):/usr/local/etc/php/7.4/php.ini

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM