1
import pymysql user = input('user>>>').strip() pwd = input('pwd>>>').strip() # 建立连接 conn = pymysql.connect( host='127.0.0.1', # localhost port=3306, user='root', password='root', db='db10', charset='utf8' ) # 拿到游标 cursor = conn.cursor() # 执行sql语句 sql = "select * from userinfo where username='%s' and password='%s'" % (user, pwd) rows = cursor.execute(sql) # 关闭游标 cursor.close() # 关闭连接 conn.close() if rows: print('登录成功', rows) else: print('登录失败', rows)
3
# 执行sql语句 sql = 'select * from userinfo where username="%s" and password="%s"' rows = cursor.execute(sql, (user, pwd))
2
3
4
5