/** * 执行SQL语句 */ public function query($sql, $link = null) { $link = $link ? $link : $this->db_link; $result = mysql_query($sql, $link); //file_put_contents('sql.txt', $sql . PHP_EOL, FILE_APPEND); //日志操作,当调试模式开启时,将所执行过的SQL写入SQL跟踪日志文件,便于DBA进行MYSQL优化。若调试模式关闭,当SQL语句执行错误时写入日志文件 if (SYS_DEBUG === false) { if ($result == false) { //获取当前运行的namespace、controller及action名称 $action_id = App::get_action_id(); $namespace_id = App::get_namespace_id(); $controller_id = App::get_controller_id(); $namespace_code = $namespace_id ? '[' . $namespace_id . ']' : ''; if (SYS_LOG === true) { Log::write($namespace_code . '[' . $controller_id . '][' . $action_id . '] SQL execute failed :' . $sql . ' Error Code:' . $this->errno() . 'Error Message:' . $this->error()); } } } else { //获取当前运行的namespace、controller及action名称 $action_id = App::get_action_id(); $namespace_id = App::get_namespace_id(); $controller_id = App::get_controller_id(); $sql_log_file = APP_ROOT . 'logs' . DIRECTORY_SEPARATOR . 'SQL_' . date('Y_m_d', $_SERVER['REQUEST_TIME']) . '.log'; $namespace_code = $namespace_id ? '[' . $namespace_id . ']' : ''; if ($result == true) { if (SYS_LOG === true) { Log::write($namespace_code . '[' . $controller_id . '][' . $action_id . ']:' . $sql, 'Normal', $sql_log_file); } } else { Controller::halt($namespace_code . '[' . $controller_id . '][' . $action_id . '] SQL execute failed :' . $sql . '<br/>Error Message:' . $this->error() . '<br/>Error Code:' . $this->errno() . '<br/>Error SQL:' . $sql); } } return $result; }
/** * 获取当前运行的Action的URL */ public static function get_self_url() { return self::create_url(App::get_controller_id() . URL_SEGEMENTATION . App::get_action_id()); }