本文整理汇总了PHP中MongoClient::setSlaveOkay方法的典型用法代码示例。如果您正苦于以下问题:PHP MongoClient::setSlaveOkay方法的具体用法?PHP MongoClient::setSlaveOkay怎么用?PHP MongoClient::setSlaveOkay使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoClient
的用法示例。
在下文中一共展示了MongoClient::setSlaveOkay方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: connect
/**
* Connects to our database
*/
public function connect()
{
// We don't need to throw useless exceptions here, the MongoDB PHP Driver has its own checks and error reporting
// Yii will easily and effortlessly display the errors from the PHP driver, we should only catch its exceptions if
// we wanna add our own custom messages on top which we don't, the errors are quite self explanatory
if (version_compare(phpversion('mongo'), '1.3.0', '<')) {
$this->_mongo = new Mongo($this->server, $this->options);
$this->_mongo->connect();
if ($this->setSlaveOkay) {
$this->_mongo->setSlaveOkay($this->setSlaveOkay);
}
} else {
$this->_mongo = new MongoClient($this->server, $this->options);
if (is_array($this->RP)) {
$const = $this->RP[0];
$opts = $this->RP[1];
if (!empty($opts)) {
// I do this due to a bug that exists in some PHP driver versions
$this->_mongo->setReadPreference(constant('MongoClient::' . $const), $opts);
} else {
$this->_mongo->setReadPreference(constant('MongoClient::' . $const));
}
}
}
}