Advertisement
Guest User

Untitled

a guest
Mar 5th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. import pymysql.cursors
  2.  
  3. class DB:
  4. def connect(self):
  5. self.conn = pymysql.connect(
  6. host=hostname,
  7. user=username,
  8. password=password,
  9. db=dbname,
  10. charset='utf8mb4',
  11. cursorclass=pymysql.cursors.DictCursor,
  12. port=3306)
  13.  
  14. def query(self, sql):
  15. try:
  16. cursor = self.conn.cursor()
  17. cursor.execute(sql)
  18. except:
  19. self.connect()
  20. cursor = self.conn.cursor()
  21. cursor.execute(sql)
  22. return cursor
  23.  
  24. db = DB()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement