This article to: The new Too Current network blog
PHP Code section/** * [logadd operation Log] * @param [string] $userid [user ID] * @param [string] $type [Type] * @param [string] $ Controller_name [Chinese name of current controller] * @param [string] $function _name [Chinese name of current method] */function Logadd($userid,$type,$controller _name,$function _name){ Combining data$data[' UserID '] =$userid;User of the current operation$data[' Type '] =$type;Type of current operation$data[' URL '] = '/HTTP '.$_server[' Http_host '].$_server[' Request_uri '];The URL address of the current action$data[' Controller '] =Controller_name;The name of the current controller$data[' Controller_name '] =$controller _name;The Chinese name of the current controller$data[' function '] =Action_name;The name of the current method$data[' Function_name '] =$function _name;The Chinese name of the current method$data[' IP '] =Getclientip();IP Address$data[' Create_time '] =Date(' Y-m-d h:i:s ',Time());Logon Hours Table name$data _fun= ' T_sys_logs_ '.Date(Y,Time()); Execute native SQL$Model=M();$results=$Model-Query(' Show Tables ');Open Library Assemble as a one-dimensional array to judge Foreach($resultsAs$k=$v){$data _table_show[] =$v[' Tables_in_dbwxapplite ']; } First determine if a table exists If(In_array(Strtolower($data _fun),$data _table_show)){ Existing table add log directly$loginLog=M($data _fun),Add($data); If($loginLog!= False){$res= [' Status ' = ' 1 ',' Result ' = ' Write Success ',' Data ' =$loginLog]; }Else{$res= [' Status ' = ' 0 ',' Result ' = ' Write Failed ',' Data ' =$loginLog]; } }Else{ Table does not exist, call stored procedure First, execute add log$code=$Model-Query("Call Spcreatetablesyslogs (".Date(Y,Time()).")"); If($code){ Data is added when the stored procedure succeeds$loginLog=M($data _fun),Add($data); If($loginLog!= False){$res= [' Status ' = ' 1 ',' Result ' = ' Write Success ',' Data ' =$loginLog]; }Else{$res= [' Status ' = ' 0 ',' Result ' = ' Write Failed ',' Data ' =$loginLog]; } }else{ //Failure $res = [' status ' = ' 0 ',' result ' = = ' stored procedure call failed ',' data ' = $loginLog]; } } return $res;}
//MysqlScript Database section-- ------------------------------ TableStructureFort_sys_logs_2017-- ----------------------------DROP TABLE IF EXISTS' t_sys_logs_2017 ';CREATE TABLE' t_sys_logs_2017 ' ( ' Logid 'Int(11)Not NULL auto_increment COMMENT' Log ID ', ' UserID 'varchar(32)Not NULL DEFAULT' 0 'COMMENT' Create Person ID ', ' Type 'varchar(8)Not NULL COMMENT' Log operation type, such as: Log in, log out, exit, change password, create registration ', ' URL 'varchar(100)Not NULL DEFAULT' www 'COMMENT' URL of current action ', ' Controller 'varchar(30)Not NULL DEFAULT' Name of Controller 'COMMENT' Name of current controller ', ' Controller_name 'varchar(30)Not NULL DEFAULT' Chinese name of controller 'COMMENT' Chinese name of current controller ', ' function 'varchar(30)Not NULL DEFAULT' Name of method 'COMMENT' Name of the current method ', ' Function_name 'varchar(30)Not NULL DEFAULT' Chinese name of method 'COMMENT' Chinese name of current method ', ' IP 'varchar(30)Not NULL DEFAULT' 255.255.255.255 'COMMENT' Current Operation client IP ', ' Create_time 'Timestamp not NULL DEFAULT ' 0000-00-00 00:00:00 ' COMMENT ' creation time ' ,< Span class= "PLN" > ' update_time ' timestamp not NULL DEFAULT 0000-00-00 00:00:00 ' on update current_timestamp COMMENT ' update Time ' , PRIMARY KEY ( ' logid ' ) Engine=innodb Auto_increment=2 DEFAULT CHARSET =utf8mb4 comment= ' Operation Log table '
This article to: The new Too Current network blog
thinkphp Execute call stored procedure add log