简体   繁体   English

数据库异常– yii \\ db \\ Exception

[英]Database Exception – yii\db\Exception

I got this error: 我收到此错误:

 Caused by: PDOException invalid data source name in C:\\wamp64\\www\\quickcar\\vendor\\yiisoft\\yii2\\db\\Connection.php at line 686 

This is the main-local.php : 这是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,
        ],
    ],
];

PDO support multiple database vendor so u need to tell which database to connect in order. PDO支持多个数据库供应商,因此您需要按顺序告诉要连接的数据库。

try this one 试试这个

'components' => [
    'db' => [
        'class' => '\yii\db\Connection',
        'dsn' => 'mysql:host=127.0.0.1;dbname=quickcar',
        'username' => 'quickcar',
        'password' => 'quickcar',
        'charset' => 'utf8',
    ],
],

if you are using different port on mysql then do like this 如果您在mysql上使用不同的端口,请这样做

'dsn' => 'mysql:host=127.0.0.1;port=3307;dbname=quickcar'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM