Created
October 2, 2017 20:06
-
-
Save emmettna/8c6293cd8ebf557a859da678b7127bf3 to your computer and use it in GitHub Desktop.
Python3 Database Dictionary Cursor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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