Example #1
0
 /**
  * Get write db link
  * 
  * @param int $cid Cluster index number
  * @param int $sid Server index number
  * @return Hush_Db_Dao
  */
 public function dbw($cid = 0, $sid = 0)
 {
     // try to get specify db firstly
     if (!$this->_getMaster($cid, $sid)) {
         // if specify db can not be found, do sharding
         $this->_doShardDb();
         $this->_doShardTable();
     }
     // get specify db server or random slave server
     $options = $this->_config->getMasterDb();
     $options['name'] = $this->dbName;
     // set db name
     return Hush_Db::dbPool($options, $this->charset);
 }
Example #2
0
File: Dao.php Project: LWFeng/hush
 /**
  * Get write db link
  * 
  * @param int $cid Cluster index number
  * @param int $sid Server index number
  * @return Hush_Db_Dao
  */
 public function dbw($cid = 0, $sid = 0)
 {
     $dbw = null;
     // try to get specific db
     $configs = $this->_getMaster($cid, $sid);
     // try to get sharded db
     if (!$configs) {
         // if specific db can not be found, do sharding
         $this->_doShardDb();
         // get specific db server or random master server
         $configs = $this->_config->getMasterDb();
     }
     // try to init db
     if ($configs) {
         $configs['name'] = $this->shardDbName ? $this->shardDbName : $this->dbName;
         $dbr = Hush_Db::dbPool($configs, $this->charset);
     }
     // try to shard table
     $this->_doShardTable();
     return $dbr;
 }