Python MySQLdb with Dictionary Cursor


/ Published in: Python
Save to your folder(s)



Copy this code and paste it in your HTML
  1. import MySQLdb
  2. import MySQLdb.cursors
  3.  
  4. class zenMySql():
  5.  
  6. def __init__(self, host, user, password, db):
  7. self.host = host
  8. self.user = user
  9. self.passwd = password
  10. self.db = db
  11.  
  12. def __del__(self):
  13. self.conn.close()
  14.  
  15. def dbConnect(self):
  16. self.conn = MySQLdb.connect(host=self.host, user=self.user, \
  17. passwd=self.passwd, db=self.db, cursorclass = MySQLdb.cursors.DictCursor)
  18. self.cur = self.conn.cursor()
  19.  
  20. def executeQuery(self, query):
  21. rowDump = []
  22. self.cur.execute(query)
  23. for row in self.cur:
  24. rowDump.append(row)
  25. return rowDump

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.