Advertisement
Guest User

Untitled

a guest
May 1st, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. def mysql_save():
  2. try:
  3. # 获取连接对象
  4. conn = pymysql.connect(host='127.0.0.1', user='root', password='mysql', database='paimai', port=3306,
  5. charset='utf8')
  6. # 获取执行工具
  7. cur = conn.cursor()
  8.  
  9. sql = """select user,password from user where user={} and password={}""".format(user_name, password)
  10.  
  11. # 执行,返回值。如果是增删改,返回受影响的行数,如果是查询,返回查询的行数
  12. count = cur.execute(sql)
  13. print(count, type(count))
  14. # 关闭
  15. conn.commit() # 提交
  16. cur.close()
  17. conn.close()
  18.  
  19. if count == 1:
  20. print('true')
  21.  
  22.  
  23.  
  24. except Exception as e:
  25. print('数据库连接错误\n', e)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement