在配置好读写分离的前提下,在thinkphp创建一个跨库的model填写数据库配置
class TestModel extends RelationModel {
protected $connection = array(
'db_type' => 'mysql',
'db_user' => 'root',
'db_pwd' => ' ',
'db_host' => 'localhost',
'db_port' => '3306',
'db_name' => 'test'
);
}
然后在相应的模块中实例化model
class TestAction {
public function test(){
/*先执行块库的实例化*/
$test = D('TestTb');
//再执行其他的读写分离
$rw = M('Test2');
}
}