寻求有关更新mysql表多文件的帮助。我正在运行以下命令并收到错误。谁可以帮我这个事。我正在从字典的值更新表。请参阅以下代码
cols = change_dict.keys()
vals = change_dict.values()
conn = MySQLdb.connect(host = "0.0.0.0",user="test",passwd="test",db='maint')
x = conn.cursor()
sql = "update details set %s = '%s' where maint_id=%s" % ( ",".join(cols), ",".join((vals)),id)
print sql
x.execute(sql)
conn.commit()
答案 0 :(得分:0)
尝试此语句
sql="UPDATE table name SET field=%s WHERE maint_id=%s", (var1, maint_id)
答案 1 :(得分:-1)
尝试以下方法:
update table set column1 = value1, column2 = value2, column3 = value3 where Condition