Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pymysql
- import traceback
- cnx = pymysql.connect(host='localhost', port=3306,
- user='root', password='', database='db',
- charset='utf8mb4',
- cursorclass=pymysql.cursors.DictCursor)
- with cnx.cursor() as cursor:
- try:
- cursor.execute("SELECT * FROM some_table")
- d = cursor.fetchall()
- for item in d:
- print(item)
- except:
- print(traceback.format_exc())
- cnx.rollback()
- cnx.commit()
- cnx.close()
Add Comment
Please, Sign In to add comment