Example #1
0
 /**
  * 查询
  * 
  * @param string $sql
  * @return PDOStatement
  */
 public function query($sql = '')
 {
     static $reconnectNum = 0;
     #添加日志功能,重置时间
     if (IS_DEBUGGING) {
         ZOL_Log::resetTime();
     }
     $this->chooseDbConn($sql);
     $sql .= $this->sqlComment;
     $query = $this->db->query($sql);
     if (empty($query)) {
         $error = $this->errorInfo();
         if ($reconnectNum < 3 && $error[0] == 'HY000' && in_array($error[1], array(2003, 2004, 2006, 2055, 2013))) {
             $this->db = null;
             $reconnectNum++;
             if ($reconnectNum > 1) {
                 usleep(50000);
             }
             return $this->query($sql);
         }
         trigger_error($error[2], E_USER_WARNING);
     }
     $reconnectNum = 0;
     #添加日志功能
     /*
     		if(IS_DEBUGGING){
     			$nowTime    = date("H:i:s");
     			$nowUrl     = str_replace("_check_mysql_query=", "", $_SERVER["REQUEST_URI"]);
     			$sql        = str_replace("\n", "",$sql);
     			$sql        = preg_replace("#\s{2,}#", " ", $sql);
     			$logContent = "{$nowUrl} [{$nowTime}][".$this->servers['slave']['host']." - ".$this->servers['slave']['database']."] SQL:".$sql." \n";
     			ZOL_Log::checkUriAndWrite(array('message'=>$logContent , 'paramName'=>'_check_mysql_query','recTime'=>true));
     		}*/
     return $query;
 }