def add_user(username, password, age, phone, email): _count, _rt_list = checkUser(username=username) if _count: return False else: _sql = 'insert into user(username, password, age, phone, email) value (%s, md5(%s), %s, %s, %s)' args = (username, password, age, phone, email) excute_mysql(_sql, args, fetch=False) return True
def get_user(): _cols = ('uid', 'username', 'password', 'age', 'phone', 'email') sql = 'select * from user' _rt = [] _count, _rt_list = excute_mysql(sql) for i in _rt_list: _rt.append(dict(zip(_cols, i))) return _rt
def validate_login(username, password): #_sql = 'select * from user where username="******" and password=md5("{password}")'.format(username=username, password=password) #为了预防SQL注入,SQL语句写成如下: sql1 = 'select * from user where username=%s and password=md5(%s)' args = (username, password) print args _count, _rt_list = excute_mysql(sql1, args) return _count != 0
def logTop(number): _rt = [] count = 1 #_sql = 'select ip, url, status, count(*) as cnt from accesslog group by ip, url, status order by cnt desc limit %s' _sql = 'select ip, url, status, count(*) as cnt from accesslog group by ip ,url, status order by cnt desc limit %s' args=(int(number),) _count, _rt_list = dbutils.excute_mysql(_sql, args) cols = ('number', 'ip', 'url', 'status', 'count') for i in _rt_list: _rt.append(dict(zip(cols,(count,i[0], i[1], i[2], i[3])))) count += 1 #print _rt return _rt
def logTop(number): _rt = [] count = 1 #_sql = 'select ip, url, status, count(*) as cnt from accesslog group by ip, url, status order by cnt desc limit %s' _sql = 'select ip, url, status, count(*) as cnt from accesslog group by ip ,url, status order by cnt desc limit %s' args = (int(number), ) _count, _rt_list = dbutils.excute_mysql(_sql, args) cols = ('number', 'ip', 'url', 'status', 'count') for i in _rt_list: _rt.append(dict(zip(cols, (count, i[0], i[1], i[2], i[3])))) count += 1 #print _rt return _rt
def upToDb(uid, username, password, age, phone, email): sql = 'update user set password=md5(%s),age=%s,phone=%s,email=%s where id=%s and username=%s' args = (password, age, phone, email, uid, username) excute_mysql(sql, args, fetch=False) return True
def delUser(uid): sql = 'delete from user where id=%s' args = (uid, ) excute_mysql(sql, args, fetch=False) return True
def checkUser(username=None, uid=None): _cols = ('uid', 'username', 'password', 'age', 'phone', 'email') sql = 'select * from user where username=%s or id=%s' args = (username,uid) _count, _rt_list = excute_mysql(sql, args) return _count, _rt_list
def checkUser(username=None, uid=None): _cols = ('uid', 'username', 'password', 'age', 'phone', 'email') sql = 'select * from user where username=%s or id=%s' args = (username, uid) _count, _rt_list = excute_mysql(sql, args) return _count, _rt_list
def add_user(username, password, age, phone, email): userlist = get_user() userinfo = {'username': username, 'password': password, 'age': age, 'phone': phone, 'email': email} _sql = 'insert into user(username, password, age, phone, email) value (%s, md5(%s), %s, %s, %s)' args = (username, password, age, phone, email) excute_mysql(_sql, args, fetch=False)
def upToDb(uid, username, password, age, phone, email): sql = 'update user set age=%s,phone=%s,email=%s where id=%s and username=%s' args = (age, phone, email, uid, username) _count, _rt_list = excute_mysql(sql, args, fetch=False)