当前位置: 首页>>代码示例>>PHP>>正文


PHP Mongo::setSlaveOkay方法代码示例

本文整理汇总了PHP中Mongo::setSlaveOkay方法的典型用法代码示例。如果您正苦于以下问题:PHP Mongo::setSlaveOkay方法的具体用法?PHP Mongo::setSlaveOkay怎么用?PHP Mongo::setSlaveOkay使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mongo的用法示例。


在下文中一共展示了Mongo::setSlaveOkay方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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));
             }
         }
     }
 }
开发者ID:rubipikachu,项目名称:xoso-lechung,代码行数:28,代码来源:EMongoClient.php

示例2: auth

 public function auth($username, $password, $db = "admin")
 {
     if ($db === "") {
         if (!$this->_mongoAuth && $this->_mongoDb) {
             $db = $this->_mongoDb;
         } else {
             $db = "admin";
         }
     }
     $server = $this->_mongoHost . ":" . $this->_mongoPort;
     if (!$this->_mongoPort) {
         $server = $this->_mongoHost;
     }
     try {
         $this->_mongo = new Mongo($server, $this->_mongoOptions);
         $this->_mongo->setSlaveOkay(true);
     } catch (Exception $e) {
         echo "Unable to connect MongoDB, please check your configurations. MongoDB said:" . $e->getMessage() . ".";
         exit;
     }
     // changing timeout to the new value
     MongoCursor::$timeout = $this->_mongoTimeout;
     //auth by mongo
     if ($this->_mongoAuth) {
         $dbs = $db;
         if (!is_array($dbs)) {
             $dbs = preg_split("/\\s*,\\s*/", $dbs);
         }
         foreach ($dbs as $db) {
             $ret = $this->_mongo->selectDb($db)->authenticate($username, $password);
             if (!$ret["ok"]) {
                 return false;
             }
         }
     } else {
         if ($this->_controlAuth) {
             if (!isset($this->_controlUsers[$username]) || $this->_controlUsers[$username] != $password) {
                 return false;
             }
             //authenticate
             if (!empty($this->_mongoUser)) {
                 return $this->_mongo->selectDB($db)->authenticate($this->_mongoUser, $this->_mongoPass);
             }
         } else {
             //authenticate
             if (!empty($this->_mongoUser)) {
                 return $this->_mongo->selectDB($db)->authenticate($this->_mongoUser, $this->_mongoPass);
             }
         }
     }
     return true;
 }
开发者ID:tolsasha,项目名称:Forum_PO,代码行数:52,代码来源:MServer.php

示例3: testSlaveOkay

    public function testSlaveOkay() {
        $conn = new Mongo("mongodb://localhost", array("replicaSet" => true, "slaveOkay" => true));
        $this->assertTrue($conn->getSlaveOkay());
        $db = $conn->somedb;
        $this->assertTrue($db->getSlaveOkay());
        $c = $db->somec;
        $this->assertTrue($c->getSlaveOkay());

        $conn->setSlaveOkay(false);
        $this->assertFalse($conn->getSlaveOkay());
        $this->assertTrue($db->getSlaveOkay());
        $this->assertTrue($c->getSlaveOkay());

        $db = $conn->somedb;
        $this->assertFalse($db->getSlaveOkay());
        $c = $db->somec;
        $this->assertFalse($c->getSlaveOkay());

        $db->setSlaveOkay(true);
        $this->assertTrue($db->getSlaveOkay());

        $c->setSlaveOkay(true);
        $this->assertTrue($c->getSlaveOkay());

        $conn->setSlaveOkay(true);
        $this->assertTrue($conn->getSlaveOkay());
    }
开发者ID:neurodrone,项目名称:mongo-php-driver,代码行数:27,代码来源:MongoTest.php


注:本文中的Mongo::setSlaveOkay方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。