Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. import pymysql.cursors
  2.  
  3. # Connect to the database.
  4. connection = pymysql.connect(host='127.0.0.1',
  5. user='root',
  6. password='',
  7. db='python',
  8. charset='utf8mb4',
  9. cursorclass=pymysql.cursors.DictCursor)
  10.  
  11. print ("connect successful!!")
  12.  
  13. try:
  14.  
  15.  
  16. with connection.cursor() as cursor:
  17.  
  18. # SQL
  19. sql = "SELECT id, number FROM scaner2 "
  20.  
  21. # Execute query.
  22. bbb = cursor.execute(sql)
  23. results = cursor.fetchall()
  24. df = list([number["number"] for number in results])
  25. print ("cursor.description: ", df)
  26.  
  27. b2 = str(input())
  28.  
  29.  
  30. if b2 in df:
  31.  
  32. w2 = "SELECT id FROM scaner2 WHERE number = srt(b2)"
  33. cursor.execute(w2)
  34. res = cursor.fetchall()
  35. print(res)
  36. else:
  37. print ('Код не найден')
  38.  
  39.  
  40. finally:
  41. # Close connection.
  42. connection.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement