Skip to content

Instantly share code, notes, and snippets.

@emmettna
Created October 2, 2017 20:06
Show Gist options
  • Save emmettna/8c6293cd8ebf557a859da678b7127bf3 to your computer and use it in GitHub Desktop.
Save emmettna/8c6293cd8ebf557a859da678b7127bf3 to your computer and use it in GitHub Desktop.
Python3 Database Dictionary Cursor
import pymysql
class DBConn:
conn_obj = None
def __init__(self):
try:
db = pymysql.connect(host="",
user="",
passwd="",
db="")
self.conn_obj = db.cursor(pymysql.cursors.DictCursor)
except Exception as e:
print("Unable to connect to DB for the following reason : "+str(e))
def query(self.query.params):
try:
self.conn_obj.execute(query, params)
if self.conn_obj.rowcount > 1:
print("Handle a case of method is correct but no effects on DB like overrind the same values")
response = "Successfull"
except Exception as e:
print("handle a case of exception")
response = "Unexpected error for the follow reason : "+str(e)
return ({'response': response})
def __del__(self):
self.conn_obj.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment