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.
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
MAMP: 6.2
PHP: 7.3.21
Update - More Context
In the php.ini file the following lines are uncommented. This is the correct php.ini file according to 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