import pymysql
class dbUtil():
def __init__(self):
self.connect = pymysql.connect(host='localhost', user='root', passwd='root', db='playmusic', charset='utf8')
self.cursor = self.connect.cursor()
def close(self):
if self.cursor:
self.close()
if self.connect:
self.close()
def exeDML(self, sql, *args):
try:
self.cursor.execute(sql, args)
count = self.connect.commit()
return count
except Exception as e:
print(e)
if self.connect:
self.connect.rollback()
finally:
self.close()
def quryone(self, sql, *args):
try:
self.cursor.execute(sql, args)
return self.cursor.fetchone()
except Exception as e:
print(e)
if self.connect:
self.connect.close()
finally:
self.close()
def quryall(self, sql, *args):
try:
self.cursor.execute(sql, args)
return self.cursor.fetchall()
except Exception as e:
print(e)
if self.connect:
self.connect.close()
finally:
self.close()
l
老师以上代码会出现这个报错,我网上查了,说是超过最大递归深度,但是我写的另外一个一模一样的代码却可以正常运行,下面的这个代码是可以正常运行的。我检查了很多遍,实在找不出有什么区别
class dbUtil():
def __init__(self):
self.connect = pymysql.connect(host='localhost', user='root', passwd='root', db='playmusic', charset='utf8')
self.cursor = self.connect.cursor()
def close(self):
if self.cursor:
self.cursor.close()
if self.connect:
self.connect.close()
def exeDML(self, sql, *args):
try:
self.cursor.execute(sql, args)
count = self.connect.commit()
return count
except Exception as e:
print(e)
if self.connect:
self.connect.rollback()
finally:
self.close()
def quryone(self, sql, *args):
try:
self.cursor.execute(sql, args)
# self.cursor.fetchone()
return self.cursor.fetchone()
except Exception as e:
print(e)
if self.connect:
self.connect.close()
finally:
self.close()
def quryall(self, sql, *args):
try:
self.cursor.execute(sql, args)
return self.cursor.fetchall()
except Exception as e:
print(e)
if self.connect:
self.connect.close()
finally:
self.close()