In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the relevant knowledge of "mysql management system operation log design example analysis". In the operation process of the actual case, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Before you start, you must make a clear distinction between the two logs, that is, the general operation log and the business operation log. What is the difference between the two?
As far as I understand it, the general operation log is the operation record of a single table, while the business operation log is a collection of a series of common operation logs.
For example, users need to buy a treasure, which has reached the point of issuing an order, and issuing an order is a business. Behind this business is a series of businesses, such as: generating orders, →, generating product snapshots, → sending a message inside the site, → deleting the corresponding baby in the shopping cart.
Such an order operation contains four parts, which can be regarded as four tables, and the corresponding operations on these four tables will realize the business.
But what I want to talk about today is not the business operation log, because the business of different projects is different, so it can not be made into a general module, but what I want to talk about is the general operation log.
There is a long explanation above, but the following practical information is about to be unveiled. Wash your face first and wake up.
First of all, where does the operation log need to be recorded? Logging is required when performing insert, update and delete operations, and the order of log execution is as follows
After the order is clear, let's take a look at a log operation class I wrote. Thank you casually in the * * version. There is a lot of repetitive code, and there is no time to optimize it.
Class LOG {protected $primaryid; protected $tbid; protected $tbname; protected $keys; protected $values; / * Parameter description * int $tbid query the id * string $tbname database table name of the specified table * / public function insert ($tbid, $tbname) {global $db / / query table comments $db- > query ('show table status where name = ". $tbname.'"'); $tb = $db- > fetch () / / insert log master table $returnid = $db- > insert (0,2, 'tb_log', array (' adminid ='. $_ SESSION ['admin'] [' id'], 'type = 1century,' tableid ='. $tbid, 'tablename = ". $tbname.'"' 'comment = ". $tb [' Comment'].'','dt = now ()') / / query field notes $db- > query ('show full columns from'. $tbname); $tb = $db- > fetchAll (); foreach ($tb as $v) {$commentArray [$v ['Field']] = $v [' Comment'] } / / query all field information, insert log from table $rs = $db- > select (0,1, $tbname,'*', 'and tbid ='. $tbid); $keys = array_keys ($rs); $values = array_values ($rs); for ($I = 0; $I)
< count($keys); $i++){ $db->Insert (0,0, 'tb_log_content', array (' logid ='. $returnid, 'tbkey = ". $keys [$I].'", 'tbvalue = ". $values [$I].'", 'comment = ". $commentArray [$keys [$I].'"')) }} public function updateStart ($tbid, $tbname) {global $db; / / query table annotations $db- > query ('show table status where name = ". $tbname.'"'); $tb = $db- > fetch () / / insert log master table $returnid = $db- > insert (0,2, 'tb_log', array (' adminid ='. $_ SESSION ['admin'] [' id'], 'type = 2 years,' tableid ='. $tbid, 'tablename = ". $tbname.'"' 'comment = ". $tb [' Comment'].'','dt = now ()') / / query pre-modification data information $rs = $db- > select (0,1, $tbname,'*', 'and tbid ='. $tbid); $keys = array_keys ($rs); $values = array_values ($rs); $this- > primaryid = $returnid; $this- > tbid = $tbid; $this- > tbname = $tbname; $this- > keys = $keys; $this- > values = $values } public function updateEnd () {global $db; / / query field notes $db- > query ('show full columns from'. $this- > tbname); $tb = $db- > fetchAll (); foreach ($tb as $v) {$commentArray [$v ['Field']] = $v [' Comment'] } / / query modified data information $rs = $db- > select (0,1, $this- > tbname,'*', 'and tbid ='. $this- > tbid); $currentvalues = array_values ($rs); / / compare the information before and after for ($I = 0; $I
< count($currentvalues); $i++){ if($this->Values [$I]! = = $currentvalues [$I]) {$db- > insert (0,0, 'tb_log_content', array (' logid ='. $this- > primaryid, 'tbkey = ". $this- > keys [$I].'", 'tbvalue = ". $this- > values [$I].'"'' 'currenttbvalue = ". $currentvalues [$I].'", 'comment = ". $commentArray [$this- > keys [$I]].'") } public function delete ($tbid, $tbname) {global $db; / / query table notes $db- > query ('show table status where name = ". $tbname.'"'); $tb = $db- > fetch () / / insert log master table $returnid = $db- > insert (0,2, 'tb_log', array (' adminid ='. $_ SESSION ['admin'] [' id'], 'type = 3 years,' tableid ='. $tbid, 'tablename = ". $tbname.'"' 'comment = ". $tb [' Comment'].'','dt = now ()') / / query field notes $db- > query ('show full columns from'. $tbname); $tb = $db- > fetchAll (); foreach ($tb as $v) {$commentArray [$v ['Field']] = $v [' Comment'] } / / query all field information, insert log from table $rs = $db- > select (0,1, $tbname,'*', 'and tbid ='. $tbid); $keys = array_keys ($rs); $values = array_values ($rs); for ($I = 0; $I)
< count($keys); $i++){ $db->Insert (0,0, 'tb_log_content', array (' logid ='. $returnid, 'tbkey = ". $keys [$I].'", 'tbvalue = ". $values [$I].'", 'comment = ". $commentArray [$keys [$I].'");}
Once introduced, you can start using it.
Select
$log- > insert (82, 'tb_member')
Update
$log- > updateStart (82, 'tb_member'); / / update operation code $log- > updateEnd ()
Delete
$log- > delete (82, 'tb_member')
As you can see, all you need is two parameters, the table ID (primary key) and the table name.
In addition, it is important to emphasize that table comments and field comments must be complete, because the recorded information contains comments in order to know which field is used for what.
Let's take a look at the finished product.
"mysql management system operation log design example analysis" content is introduced here, thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.