Advertisement
Guest User

Untitled

a guest
Aug 24th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. import pymysql
  2.  
  3. # Connect to the database
  4. connection = pymysql.connect(host='localhost',
  5. user='root',
  6. password='',
  7. db='usermaster',
  8. charset='utf8mb4',
  9. cursorclass=pymysql.cursors.DictCursor)
  10. try:
  11.  
  12. with connection.cursor() as cursor:
  13. # Read a single record
  14. sql = "SELECT * From usermaster"
  15. cursor.execute(sql)
  16. result = cursor.fetchone()
  17. print(result)
  18. finally:
  19. connection.close()
  20.  
  21. #result: {'username': 'admin', 'password': 'Administrator', 'userid': 'admin'}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement