public function __get($db)
{
if ($db == 'rlink') {
//如果没有指定从数据库,则使用 master
if (!isset($this->conf['slaves']) || empty($this->conf['slaves'])) {
$this->rlink = $this->wlink;
return $this->rlink;
}
$n = mt_rand(0, count($this->conf['slaves']) - 1);
$conf = $this->conf['slaves'][$n];
$this->rlink = $this->connect($conf['host'], $conf['username'], $conf['password'], $conf['dbname'], isset($conf['replicaSet']) ? $conf['replicaSet'] : '');
return $this->rlink;
} elseif ($db == 'wlink') {
$conf = $this->conf['master'];
$this->wlink = $this->connect($conf['host'], $conf['username'], $conf['password'], $conf['dbname'], isset($conf['replicaSet']) ? $conf['replicaSet'] : '');
return $this->wlink;
}
return false;
}