yii2学习笔记 --- 基础版配置链接多个数据库

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/weixin_41120504/article/details/89278617

打开/config/db.php

return [
    'class' => 'yii\db\Connection',
    'dsn' => 'mysql:host=localhost;dbname=yii2basic',
    'username' => 'root',
    'password' => '',
    'charset' => 'utf8',

    // Schema cache options (for production environment)
    //'enableSchemaCache' => true,
    //'schemaCacheDuration' => 60,
    //'schemaCache' => 'cache',
];

把配置改为 


return [
    'db' => [
       'class' => 'yii\db\Connection',
        'dsn' => 'mysql:host=localhost;dbname=yii2basic',
        'username' => 'root',
        'password' => '',
        'charset' => 'utf8',
    ],
    
    // Schema cache options (for production environment)
    //'enableSchemaCache' => true,
    //'schemaCacheDuration' => 60,
    //'schemaCache' => 'cache',
];

然后报错

打开/config/web.php

加上 $config['components'] = array_merge($config['components'], $db);

猜你喜欢

转载自blog.csdn.net/weixin_41120504/article/details/89278617