Beispiel #1
0
 private function connect($strName)
 {
     $ret = ral_get_service($strName);
     $intServerNum = array_rand($ret['server']);
     $server = $ret['server'][$intServerNum];
     $dbConf = array('host' => $server['ip'], 'port' => $server['port'], 'uname' => $ret['user'], 'passwd' => base64_decode($ret['passwd']), 'flags' => 0, 'dbname' => $ret['extra']['dbname']);
     $mysql = mysqli_init();
     $this->_timer->start();
     $ret = $mysql->real_connect($dbConf['host'], $dbConf['uname'], $dbConf['passwd'], $dbConf['dbname'], $dbConf['port'], NULL, $dbConf['flags']);
     $time = $this->_timer->stop();
     $this->_connectTime += $time;
     $this->_arrMysql[$strName] = $mysql;
     if (!$ret) {
         Bd_Db_RALLog::warning(RAL_LOG_SUM_FAIL, "SplitDB", $strName, "connect", "{$host}:{$port}", 0, 0, 0, 0, 0, $dbConf['dbname'], "", $mysql->errno, $mysql->error);
         return false;
     }
     //set charset while connect
     if ($this->_strCharset) {
         $mysql->set_charset($this->_strCharset);
     }
     return true;
 }
Beispiel #2
0
 public function ralConnect($strName)
 {
     $ret = ral_get_service($strName);
     $intServerNum = array_rand($ret['server']);
     $server = $ret['server'][$intServerNum];
     $this->dbConf = array('host' => $server['ip'], 'port' => $server['port'], 'uname' => $ret['user'], 'passwd' => base64_decode($ret['passwd']), 'flags' => 0, 'dbname' => $ret['extra']['dbname']);
     $this->isConnected = $this->mysql->real_connect($this->dbConf['host'], $this->dbConf['uname'], $this->dbConf['passwd'], $this->dbConf['dbname'], $this->dbConf['port'], NULL, $this->dbConf['flags']);
     if (!$this->isConnected) {
         Bd_Db_RALLog::warning(RAL_LOG_SUM_FAIL, "Bd_DB", $this->{$dbConf}['dbname'], "connect", "{$this->{$dbConf}['host']}:{$this->{$dbConf}['port']}", 0, 0, 0, 0, 0, $this->{$dbConf}['dbname'], "", $this->mysql->errno, $this->mysql->error);
     }
     return $this->isConnected;
 }