一:配置文件增加db2连接
'db2' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=dbname',
'username' => '',
'password' => '',
'charset' => 'utf8',
'tablePrefix' => 't_',、
二:db2的model增加get方法
public static function getDb()
{
return Yii::$app->get('db2');
}