thinkphp3.0,读写分离,同一个方法中跨库操作

来源:互联网 发布:mybatis sql 编辑:程序博客网 时间:2024/06/11 23:59


在配置好读写分离的前提下,在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');

}

}

原创粉丝点击