【发布时间】:2016-06-16 21:17:54
【问题描述】:
当我将 yii2 与 postgresql 数据库一起使用时出现此错误。
SQLSTATE[HY000] [2002] No such file or directory
Caused by: PDOException
SQLSTATE[HY000] [2002] No such file or directory
我这样配置文件 main-local.php :
<?php
return [
'components' => [
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'pgsql:host=127.0.0.1;port=5432;dbname=dbname',
'username' => 'user',
'password' => 'pass',
'charset' => 'utf8',
],
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '@common/mail',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure a transport
// for the mailer to send real emails.
'useFileTransport' => true,
],
],
];
顺便说一句,当我使用 mysql 时,它正在工作。
【问题讨论】:
-
检查
http://localhost/requirements.php(docs) 的输出并查看您的服务器中是否安装了PDO PostgreSQL 扩展。 -
也可以试试
localhost而不是127.0.0.1 -
我这样做了,但我得到了同样的错误
-
ok 然后检查您的
php.ini文件(或phpinfo())并查找PostgreSQL 套接字路径以查看它们是否设置正确。我对 PostgreSQL 不太了解,但使用 MySQL,它们看起来像:mysql.default_socket= /tmp/mysql.sock、mysqli.default_socket= /tmp/mysql.sock和pdo_mysql.default_socket= /tmp/mysql.sock -
在 php.ini 中没有用于 postgresql 的套接字部分或注释
标签: php database postgresql pdo yii2