def execute(self, sql=None, params=None, db=None):
if sql is None:
return None
resultRow = []
with contextlib.\
closing(mysql.connector.connect(host=str(self.host),
port=int(self.port),
user=str(self.user),
password=str(self.passwd),
db=str(self.database) if not db else db)) as conn:
conn.autocommit = True
with contextlib.closing(conn.cursor(buffered=True)) as cursor:
cursor.execute(sql, params)
try:
resultRow = cursor.fetchall()
except errors.InterfaceError:
# Raised on empty result - DML
resultRow = []
return resultRow
评论列表
文章目录