예제 #1
0
파일: DbProxy.php 프로젝트: suyuanen/trotri
 /**
  * (non-PHPdoc)
  * @see \tfc\db\Statement::getDriver()
  */
 public function getDriver($autoOpen = true)
 {
     if ($this->_driver === null) {
         $this->_driver = new Driver($this->getDsn(), $this->getUsername(), $this->getPassword(), $this->getCharset());
         if (($caseFolding = $this->getCaseFolding()) !== null) {
             $this->_driver->setCaseFolding($caseFolding);
         }
     }
     if (!$autoOpen) {
         return $this->_driver;
     }
     if ($this->_driver->getIsConnected()) {
         return $this->_driver;
     }
     $maxRetry = $this->getRetry();
     for ($retry = 0; $retry < $maxRetry; $retry++) {
         try {
             $this->_driver->open();
             $message = 'PDO Connect DB Successfully!';
             $code = 0;
         } catch (ErrorException $e) {
             $message = 'PDO Connect DB Failed! ' . $e->getMessage();
             $code = $e->getCode();
         }
         $event = array('msg' => $message, 'retry' => $retry, 'config' => serialize($this->getConfig()));
         if ($code === 0) {
             Log::notice($event, __METHOD__);
             return $this->_driver;
         }
         Log::warning($event, $code, __METHOD__);
     }
     return null;
 }
예제 #2
0
 /**
  * CURL方式提交数据
  * @param string $pathinfo
  * @param array $params
  * @param string $method
  * @return mixed
  */
 public function talk($pathinfo, array $params = array(), $method = 'GET')
 {
     $ral = $this->getRal();
     $ral->setLogId(Log::getId());
     $maxRetry = $this->getRetry();
     for ($retry = 0; $retry < $maxRetry; $retry++) {
         try {
             $result = $ral->talk($pathinfo);
             $message = 'Ral Exec Curl Successfully!';
             $code = 0;
         } catch (ErrorException $e) {
             $message = 'Ral Exec Curl Failed! ' . $e->getMessage();
             $code = $e->getCode();
             $result = false;
         }
         $event = array('msg' => $message, 'retry' => $retry, 'pathinfo' => $pathinfo, 'params' => serialize($params), 'method' => $method, 'config' => serialize($this->getConfig()));
         if ($result !== false) {
             Log::notice($event, __METHOD__);
             return $result;
         }
         Log::warning($event, $code, __METHOD__);
     }
     return $result;
 }