import pymysql
class MySqlUtil(object):
def __init__(self):
self.conn = pymysql.connect(host=db_host,
user=db_user,
password=db_pwd,
db=db)
self.cursor = self.conn.cursor()
def get_data_from_db(self, sql):
try:
self.cursor.execute(sql)
results = self.cursor.fetchall()
return results
except pymysql.Error as e:
print('Mysql get_data_from_db Error {0}:'.format(e))
def exec_db(self, sql):
try:
cur = self.conn.cursor()
cur.execute(sql)
self.conn.commit()
except pymysql.Error as e:
print('Mysql exec_db Error {}'.format(e))
def __del__(self):
self.cursor.close()