A MySQL Stored Procedure

Source: Internet
Author: User

I wrote it myself in the afternoon and used it for the company's products. I wrote the stored procedure for the first time. Send the code. If you have any questions, ask me.

 

 Delimiter $ </P> <p> drop procedure if exists 'tsts _ user '. 'proc _ login' $ </P> <p> Create definer = 'root' @ 'localhost' procedure 'proc _ login' (ID varchar (50 ), PWD varchar (255), ptypeuser int, serverip varchar (20), IP varchar (50), out result INT) <br/> begin </P> <p> # return record <br/> # declare ploginid varchar (50); <br/> set @ ploginid = NULL; <br/> set @ ppwd = NULL; <br/> set @ pusertype = NULL; <br/> set @ pendtime = NULL; <Br/> set result = NULL; </P> <p> select @ ploginid: = 'loginid', @ ppwd: = 'Password', @ pusertype: = ptype, @ pendtime: = endtime, name, groupname, area, notlogin, validdate, <br/> viewnews, viewgp, viewqh, viewwp, viewwh, viewgg, userlevel, memo, viewgp_max, viewqh_max, viewwp_max, <br/> viewwh_max, viewgg_max, usercfg, begintime, usedtotaltime, <br/> isonline, serverip from product P where loginid = ID; </P> <p> # If the account does not exist <br/> If (@ plogini D is null) Then <br/> set result = 1; <br/> else <br/> # If the account exists, but the password is incorrect <br/> If (@ ppwd is null or @ ppwd! = PWD) Then <br/> set result = 2; <br/> else <br/> # If the account exists and the password is correct, but it expired <br/> If (@ pendtime is null or now ()> @ pendtime) Then <br/> set result = 3; <br/> else <br/> # If the account exists, the password is correct, and the account has not expired, however, the logon type is incorrect. <br/> If (@ pusertype is null or ptypeuser not in (0, 16, 18, @ pusertype) Then <br/> set result = 4; <br/> else <br/> # update the product set last_access_time = now (), login_times = login_times + 1, isonline = 1, serverip = serverip, last_access_ip = IP where loginid = ID; <br/> end if; </P> <p> # If result is null, it is changed to 0 <br/> If (result is null) Then <br/> set result = 0; <br/> end if; </P> <p> end $ </P> <p> delimiter;

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.