老师您好
想请问 这段代码中为什么会用回滚 如果con存在也就是说连接到了数据库 就要回滚? 不明白这就为什么回滚
def execute_dml(self,sql,args):
"""
可以执行dml语句,用于数据的增删改
"""
# error handling
try:
# execute sql
self.cursor.execute(sql,args)
# commit sql
self.con.commit()
except Exception as e:
print(e)
if self.con:
self.con.rollback()
finally:
self.close()
问题二
看了其他同学的问题 *args代表参数的不确定长度 那么我要是有不同长度的参数 比如
Firstname="Sita", Lastname="Sharma", Age=22, Phone=1234567890)
Firstname="John", Lastname="Wood", Email="johnwood@nomail.com", Country="Wakanda", Age=25, Phone=9876543210)
那么
sql='INSERT INTO table_user VALUES(0,%s,%s,%s,%s)' 这里面参数部分该怎样写呢