我收到此错误:
Caused by: PDOException invalid data source name in C:\wamp64\www\quickcar\vendor\yiisoft\yii2\db\Connection.php at line 686
这是main-local.php
:
return [
'components' => [
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'quickcar',
'username' => 'quickcar',
'password' => 'quickcar',
'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,
],
],
];
答案 0 :(得分:1)
PDO
支持多个数据库供应商,因此您需要按顺序告诉要连接的数据库。
尝试这个
'components' => [
'db' => [
'class' => '\yii\db\Connection',
'dsn' => 'mysql:host=127.0.0.1;dbname=quickcar',
'username' => 'quickcar',
'password' => 'quickcar',
'charset' => 'utf8',
],
],
如果您在mysql上使用其他端口,请这样做
'dsn' => 'mysql:host=127.0.0.1;port=3307;dbname=quickcar'