python3 pymysql實現事務處理

try:
    cursor.execute(sql_1)  
    cursor.execute(sql_2)  
    cursor.execute(sql_3)  
except Exception as e:
    connect.rollback()  # 事務回滾
    print('事務處理失敗', e)
else:
    connect.commit()  # 事務提交
    print('事務處理成功', cursor.rowcount)# 關閉鏈接
cursor.close()
connect.close()
相關文章
相關標籤/搜索