Guest User

Untitled

a guest
Jun 7th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. import pymysql
  2. import traceback
  3.  
  4. cnx = pymysql.connect(host='localhost', port=3306,
  5. user='root', password='', database='db',
  6. charset='utf8mb4',
  7. cursorclass=pymysql.cursors.DictCursor)
  8.  
  9. with cnx.cursor() as cursor:
  10. try:
  11. cursor.execute("SELECT * FROM some_table")
  12. d = cursor.fetchall()
  13. for item in d:
  14. print(item)
  15. except:
  16. print(traceback.format_exc())
  17. cnx.rollback()
  18.  
  19. cnx.commit()
  20. cnx.close()
Add Comment
Please, Sign In to add comment