Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def mysql_save():
- try:
- # 获取连接对象
- conn = pymysql.connect(host='127.0.0.1', user='root', password='mysql', database='paimai', port=3306,
- charset='utf8')
- # 获取执行工具
- cur = conn.cursor()
- sql = """select user,password from user where user={} and password={}""".format(user_name, password)
- # 执行,返回值。如果是增删改,返回受影响的行数,如果是查询,返回查询的行数
- count = cur.execute(sql)
- print(count, type(count))
- # 关闭
- conn.commit() # 提交
- cur.close()
- conn.close()
- if count == 1:
- print('true')
- except Exception as e:
- print('数据库连接错误\n', e)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement