MySQL Subversion practical notes (iii)--user Login (ii): How to save the user action log

Source: Internet
Author: User

Copyright NOTICE: NOTE-taker fugitive pawns love freedom, advocating sharing. But this note stems from the www.jtthink.com (programmer in the awkward way) Judging teacher's "web-level MySQL subversive combat course." For reprint please respect the teacher Labor, retain the judging teacher attribution and course source address.

  Now we go on to the next lesson and complete the second function, which logs a log regardless of success.

First, we review the contents of the previous lesson, we add a field user_id in the User_log table.

add a line of code to the stored procedure in the previous lesson, as follows:

BEGIN    Set @gid=0; Set @user_name="'; Set @_result='Login sucess'; SELECTIduser_name  into @gid,@user_name  fromUser_sysWHERE user_name=_user_name  andUser_pwd=_user_pwd LIMIT1; IF @gid=0  Then#登录不成功SET @_result='Login Error'; END IF; INSERT  intoUser_log (user_id, Log_type)VALUES(@gid,@_result); #<-write to the Log table, this lesson addedSELECT *  from(SELECT @_result  as_result) A, (SELECT @gid,@user_name) b; END

We call again, tested to change the log File table User_log to the MyISAM engine.

  

  

  

Second, we first pour 100,000 test data into the log table.

BEGIN    SET @num=1;  while @num<100000 DoINSERT  intoUser_log (Log_type,user_id)VALUES('Log Success', Floor(Rand()*100000)); END  while;END;

Third, we envision a need: for example, there is a list to view the user action log of the current system through a page.

Required display 1) User ID 2) User name 3) log time.

First we enter the following statement, associating two tables:

SELECT A.user_namefromWHERE a.id=B.user_idorder  by desc  0,ten;

In the User_log table, we add a redundant field: user_name.

Then I user_log the table empty, new query:

Call Sp_user_login (' user3213 ', ' password ');

  

  

previous:MySQL Subversion practical notes (ii)--User login (i): the magic of unique index

MySQL Subversion practical notes (iii)--user Login (ii): How to save the user action log

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.