更新时间:2022-02-01 22:36:05
在我们的对话中,问题是由安装了多个版本的PHP引起的,并且Apache正在加载与预期的PHP 7.3不同的PHP(7.2)版本.
As from our conversation, the issue was caused by having multiple versions of PHP installed and Apache was loading a different version of PHP (7.2) than the expected PHP 7.3.
要解决此问题,请运行以下命令:
To resolve the issue run the following commands:
sudo a2dismod php7.2
sudo a2enmod php7.3
这将禁止Apache加载php7.2,而改为加载php7.3.
This will disable php7.2 from being loaded by Apache and load php7.3 instead.
对于您的DSN(数据源名称),您当前的配置使用的是unix_socket
,它似乎不是Postgresql DSN的有效选项.此外,缺少用于unix_socket参数的$params['socket']
.
For your DSN (data source name), your current configuration is using a unix_socket
which does not appear to be a valid option for the postgresql DSN. Additionally the $params['socket']
to be used for the unix_socket parameter is missing.
有关更多详细信息,请参见: https://www. php.net/manual/en/ref.pdo-pgsql.connection.php
For more details see: https://www.php.net/manual/en/ref.pdo-pgsql.connection.php
如果数据库服务器正在侦听默认端口(5432),则可以使用:
If the database server is listening on the default port (5432) you can use:
try {
$dsn = vsprintf('pgsql:host=%s;port=%s;dbname=%s;user=%s;password=%s', [
'host' => '[IP Address]',
'port' => '5432',
'dbname' => '[dbname]',
'user' => '[username]',
'password' => '[password]',
]);
$pdo = new PDO($dsn);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
echo $e->getMessage();
} catch (Throwable $e) {
echo $e->getMessage();
}
DSN应该生成: https://3v4l.org/aFKAW
pgsql:host=[IP Address];port=5432;dbname=[dbname];user=[username];password=[password]