Cml\Db\MongoDB\MongoDB::__get PHP Method

__get() public method

魔术方法 自动获取相应db实例
public __get ( string $db ) : resource
$db string 要连接的数据库类型
return resource MongoDB 连接标识
    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;
    }