getReadConnection() public static method

Get a read connection
public static getReadConnection ( string $connectionGroupName = 'default' ) : Shanty_Mongo_Connection
$connectionGroupName string The connection group name
return Shanty_Mongo_Connection
コード例 #1
0
ファイル: Document.php プロジェクト: rremigius/Shanty-Mongo
 /**
  * Fetch an instance of MongoDb
  * 
  * @param boolean $writable
  * @return MongoDb
  */
 public function _getMongoDb($writable = true)
 {
     if (is_null($this->getConfigAttribute('db'))) {
         require_once 'Shanty/Mongo/Exception.php';
         throw new Shanty_Mongo_Exception('Can not fetch instance of MongoDb. Document is not connected to a db.');
     }
     if ($writable) {
         $connection = Shanty_Mongo::getWriteConnection($this->getConfigAttribute('connectionGroup'));
     } else {
         $connection = Shanty_Mongo::getReadConnection($this->getConfigAttribute('connectionGroup'));
     }
     return $connection->selectDB($this->getConfigAttribute('db'));
 }
コード例 #2
0
ファイル: Collection.php プロジェクト: coen-hyde/shanty-mongo
 public static function getConnection($writable = true)
 {
     if ($writable) {
         $connection = Shanty_Mongo::getWriteConnection(static::getConnectionGroupName());
     } else {
         $connection = Shanty_Mongo::getReadConnection(static::getConnectionGroupName());
     }
     return $connection;
 }
コード例 #3
0
ファイル: MongoTest.php プロジェクト: renepardon/Shanty-Mongo
 /**
  * @depends testGetWriteConnection
  * @expectedException Shanty_Mongo_Exception
  */
 public function testNoReadConnections()
 {
     Shanty_Mongo::getReadConnection('users');
 }
コード例 #4
0
ファイル: Document.php プロジェクト: coen-hyde/shanty-mongo
 /**
  * Fetch an instance of MongoDb
  * 
  * @param boolean $writable
  * @return MongoDb
  */
 public function _getMongoDb($writable = true)
 {
     if (is_null($this->getConfigAttribute('db'))) {
         require_once 'Shanty/Mongo/Exception.php';
         throw new Shanty_Mongo_Exception('Can not fetch instance of MongoDb. Document is not connected to a db.');
     }
     if ($writable) {
         $connection = Shanty_Mongo::getWriteConnection($this->getConfigAttribute('connectionGroup'));
     } else {
         $connection = Shanty_Mongo::getReadConnection($this->getConfigAttribute('connectionGroup'));
     }
     $temp = $connection->selectDB($this->getConfigAttribute('db'));
     # Tells replica set how many nodes must have the data before success
     //		$temp->w = 2;
     return $temp;
 }
コード例 #5
0
ファイル: Collection.php プロジェクト: rafeca/Shanty-Mongo
 /**
  * Get an instance of MongoDb
  * 
  * @return MongoDb
  * @param boolean $useSlave
  */
 public static function getMongoDb($writable = true)
 {
     if (!static::hasDbName()) {
         require_once 'Shanty/Mongo/Exception.php';
         throw new Shanty_Mongo_Exception(get_called_class() . '::$_db is null');
     }
     if ($writable) {
         $connection = Shanty_Mongo::getWriteConnection(static::getConnectionGroupName());
     } else {
         $connection = Shanty_Mongo::getReadConnection(static::getConnectionGroupName());
     }
     return $connection->selectDB(static::getDbName());
 }