Python 更新sql

def updateSystemAccount(response):
    print('--------------返回數據是',response.json)
    
    host = 'xxx-mysql-m.a.pa.com'
    user = 'hfqa'
    passwd = 'qn3p@bI0qg'
    db = 'dcloud_pack_account_db'
    conn = pymysql.connect(host,user,passwd,db)
    cur = conn.cursor()
    
    accountId = response.json['data']['id']
    sql_update = "update t_standard_account set is_deleted = '%d' where id = %d"
    
    try:
        cur.execute(sql_update % (1,accountId))  #像sql語句傳遞參數
        #提交
        conn.commit()
        print('update成功')
        
    except Exception as e:
        #錯誤回滾
        conn.rollback()
    finally:
        conn.close()    

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章