THINKPHP项目开发中的日志记录
发布:smiling 来源: PHP粉丝网 添加日期:2014-04-11 14:38:03 浏览: 评论:0
1、建立日志表
- CREATE TABLE `logs` (
- `id` int(11) NOT NULL auto_increment,
- `guid` varchar(100) character set utf8 NOT NULL,
- `addtime` timestamp NOT NULL default CURRENT_TIMESTAMP,
- `account` varchar(100) character set utf8 NOT NULL,
- `nickname` varchar(100) character set utf8 NOT NULL,
- `app` varchar(100) character set utf8 NOT NULL,
- `action` varchar(100) character set utf8 NOT NULL,
- `method` varchar(100) character set utf8 NOT NULL,
- `query_string` text character set utf8 NOT NULL,
- `is_desc` varchar(100) character set utf8 NOT NULL,
- `desc` varchar(100) character set utf8 NOT NULL,
- `ipaddr` varchar(100) character set utf8 NOT NULL,
- `unique_flag` varchar(100) character set utf8 NOT NULL,
- PRIMARY KEY (`id`)
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ;
2、Common/common.php里面进行方法的定义:
- function getGlobalSkypeLogDbConfig() {
- $global_skype_db_config = array(
- 'dbms' => C('DB_TYPE'),
- 'username' => C('DB_USER'),
- 'password' => C('DB_PWD'),
- 'hostname' => C('DB_HOST'),
- 'database' => C('DB_NAME'),
- );
- return $global_skype_db_config;
- }
- function addOperationLog($desc=NULL, $unique_flag='system', $app=APP_NAME, $action=MODULE_NAME, $method=ACTION_NAME) {
- $global_skype_db_config = getGlobalSkypeLogDbConfig();
- static $global_skype_log_db_conn;
- if (!$global_skype_log_db_conn) {
- $global_skype_log_db_conn = mysql_connect($global_skype_db_config['hostname'], $global_skype_db_config['username'], $global_skype_db_config['password']);
- }
- if (!$global_skype_log_db_conn) {
- die('Mysql_Error:' . __FILE__ . '|' . __LINE__ . '|' . mysql_error());
- }
- mysql_query('use ' . $global_skype_db_config['database'], $global_skype_log_db_conn);
- mysql_query('set names utf8 ', $global_skype_log_db_conn);
- $account = getAdminAccount();
- $nickname = getAdminNickname();
- $user_id = getAdminUserId();
- $ipaddr = get_client_ip();
- $query_string = print_r(array_merge($_GET, $_POST), true);
- $desc = $desc;
- $is_desc = 0;
- $unique_flag = $unique_flag;
- if ($desc) {
- $is_desc = 1;
- }
- $insert_time = date('Y-m-d H:i:s');
- $query = "INSERT INTO `" . C('LOG_DB_TABLE') . "` (`guid`,`account`,`nickname`,`addtime`,`app`,`action`,
- `method`,`query_string`,`is_desc`,`desc`,`ipaddr`,`unique_flag`) VALUES ('$user_id','$account','$nickname','$insert_time','$app',
- '$action','$method','$query_string','$is_desc','$desc','$ipaddr','$unique_flag');";
- return mysql_query($query, $global_skype_log_db_conn);
- }
- function getAdminAccount() {
- return $_SESSION['loginAccount'];
- }
- function getAdminNickname() {
- return $_SESSION['loginUserName'];
- }
- function getAdminUserId() {
- return $_SESSION[C('USER_AUTH_KEY')];
- }
在其他操作类里调用addOperationLog();即可.
Tags: THINKPHP 项目开发 日志
相关文章
- ·ThinkPHP中自定义错误页面和提示页面 (2013-11-15)
- ·ThinkPHP中Ajax返回(2013-11-15)
- ·ThinkPHP中处理表单中注意(2013-11-15)
- ·ThinkPHP中I(),U(),$this->post()等函数(2013-11-15)
- ·ThinkPHP中公共函数路径和配置项路径的映射(2013-11-15)
- ·ThinkPHP中公共配置文件和各自项目中的配置文件组合(2013-11-15)
- ·ThinkPHP在控制器里的javascript代码不能执行解决方法(2013-11-29)
- ·ThinkPHP3.0略缩图不能保存到子目录(2013-12-03)
- ·thinkphp的循环结构(2014-01-10)
- ·thinkphp特殊标签使用(2014-01-10)
- ·thinkphp模板输出汇总(2014-01-10)
- ·thinkphp模板的赋值与替换(2014-01-10)
- ·thinkphp连贯操作(2014-01-10)
- ·thinkphp区间查询、统计查询、SQL直接查询(2014-01-10)
- ·thinkphp的普通查询与表达式查询(2014-01-10)
- ·RBAC类在ThinkPHP中的四种使用方法(2014-01-10)
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)