/** * 查询 * * @param string $sql * @return PDOStatement */ public function query($sql = '') { static $reconnectNum = 0; #添加日志功能,重置时间 if (IS_DEBUGGING) { LJL_Log::resetTime(); } $this->chooseDbConn($sql); $sql .= $this->sqlComment; $query = $this->db->query($sql); if (empty($query)) { $error = $this->errorInfo(); if ($reconnectNum < 5 && $error[0] == 'HY000') { $this->db = null; $reconnectNum++; if ($reconnectNum > 1) { sleep($reconnectNum); } return $this->query($sql); } trigger_error($error[2], E_USER_WARNING); } $reconnectNum = 0; #添加日志功能 if (IS_DEBUGGING && isset($_SERVER["REQUEST_URI"])) { $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"; LJL_Log::checkUriAndWrite(array('message' => $logContent, 'paramName' => '_check_mysql_query', 'recTime' => true)); } return $query; }