3.1.3 - 普通 - 未处理
在多个model 下存在bug,修改后如下protected function multiConnect($master=false) {
static $_config = array();
$modelname=$this->model;
if(empty($_config[$modelname])) {
// 缓存分布式数据库配置解析
foreach ($this->config as $key=>$val){
$_config[$modelname][$key] = explode(',',$val);
}
}
// 数据库读写是否分离
if(C('DB_RW_SEPARATE')){
// 主从式采用读写分离
if($master)
// 主服务器写入
$r = floor(mt_rand(0,C('DB_MASTER_NUM')-1));
else{
if(is_numeric(C('DB_SLAVE_NO'))) {// 指定服务器读
$r = C('DB_SLAVE_NO');
}else{
// 读操作连接从服务器
$r = floor(mt_rand(C('DB_MASTER_NUM'),count($_config[$modelname]['hostname'])-1)); // 每次随机连接的数据库
}
}
}else{
// 读写操作不区分服务器
$r = floor(mt_rand(0,count($_config[$modelname]['hostname'])-1)); // 每次随机连接的数据库
}
$db_config = array(
'username' => isset($_config[$modelname]['username'][$r])?$_config[$modelname]['username'][$r]:$_config[$modelname]['username'][0],
'password' => isset($_config[$modelname]['password'][$r])?$_config[$modelname]['password'][$r]:$_config[$modelname]['password'][0],
'hostname' => isset($_config[$modelname]['hostname'][$r])?$_config[$modelname]['hostname'][$r]:$_config[$modelname]['hostname'][0],
'hostport' => isset($_config[$modelname]['hostport'][$r])?$_config[$modelname]['hostport'][$r]:$_config[$modelname]['hostport'][0],
'databa
'dsn' => isset($_config[$modelname]['dsn'][$r])?$_config[$modelname]['dsn'][$r]:$_config[$modelname]['dsn'][0],
'params' => isset($_config[$modelname]['params'][$r])?$_config[$modelname]['params'][$r]:$_config[$modelname]['params'][0],
);
return $this->connect($db_config,$r);
}
