1.找到 yii2-app-basic\config\db.php 数据库配置文件 添加这段代码
2.db.php 代码
<?php
return [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=tp',
'username' => 'root',
'password' => '你的密码',
'charset' => 'utf8',
'slaveConfig' => [
'username' => 'root',
'password' => '你的密码',
'attributes' => [
//use a smaller connection timeout
PDO::ATTR_TIMEOUT => 10, // 请求超时时间
],
],
// 配置从服务器组
'slaves' => [
[
'dsn' => 'mysql:host=192.168.0.2;dbname=tp'
]
]
// Schema cache options (for production environment)
//'enableSchemaCache' => true,
//'schemaCacheDuration' => 60,
//'schemaCache' => 'cache',
];