import pymysql
ecshop=pymysql.connect('localhost','root','root','ecshop')
curs=ecshop.cursor() #建立游标
sql="delete from ecs_user_address where tel='19945020111'"
try:
curs.execute(sql)
ecshop.commit()
except:
ecshop.rollback()
print('wrong')
ecshop.close()

python DB API2.0的事务提供了两个方法commit或roallback;
在python编程中,当游标建立之时,就自动开始了一个隐形的数据库事务;
commit()方法提交游标的所有更新操作;rollback()方法回滚当前游标的所有操作;

相关文章:

  • 2021-07-16
  • 2022-01-19
  • 2022-12-23
  • 2022-01-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-17
猜你喜欢
  • 2023-03-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案