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