php - 更新到 macOS Big Sur 后,我无法使用 MAMP 连接到我的 PostgreSQL 数据库
问题描述
代码
这是引发错误的代码。
try {
$myPDO = new PDO('pgsql:host=127.0.0.1:5432;dbname=test', 'test', '');
} catch (\Throwable $th) {
echo var_dump($th);
}
错误
这是我从 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
}
版本
我正在使用的软件版本列表。
操作系统:macOS 大苏尔
MAMP : 6.2
PHP : 7.3.21
更新 - 更多上下文
在php.ini
文件中,以下行未注释。php.ini
根据 PHP Info,这是正确的文件。
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 驱动程序。我通过Homebrew安装了包含此驱动程序的PHP 7.4 :
brew install php@7.4
确保将其设为默认 PHP 版本。我正在使用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
您可以在此处找到 php.ini(以防您需要迁移配置):/usr/local/etc/php/7.4/ php.ini
推荐阅读
- csv - 试图将一条恒定斜率线拟合到两个特定范围的数据点
- spring-data-jpa - 如何从自动配置类添加 ImplicitNamingStrategy
- sql - 我们可以在使用连接时在另一个 SQL 查询中插入一个 SQL 查询吗?
- amazon-web-services - 如何将现有的 AWS WAF ACL 导入 terraform?
- spring - JavaMailSender with Exception write Multipart
- java - 如何创建 Maven 库(不可执行的 JAR)
- javascript - 解析导致查询失败的 Cloud Code 语法差异
- java - 使用 Jersey 的文件上传 API 抛出空指针异常错误
- codeigniter - Codeigniter:如何在视图中检索 foreach 函数中的数据
- google-chrome - 二进制路径的量角器配置