[英]Mysql syntax error in python
I have 5 MySQL columns. 我有5个MySQL专栏。 I want to insert data into my columns with a for loop. 我想使用for循环将数据插入到我的列中。 But I always get an error. 但是我总是会出错。
SQL query: SQL查询:
for i in range(5):
sql = "INSERT INTO fighters({},{}) VALUES(%s,%s) WHERE clan=%s".format("shot_" + str(i), "damage_" + str(i))
cur.execute(sql, (shot, damage, clanname)
conn.commit()
Error: 错误:
pymysql.err.ProgrammingError: (1064, u"You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'WHERE clan='blacks'' at line 1")
You need to update rather than insert: 您需要更新而不是插入:
sql = "UPDATE FIGHTERS SET shot_{0} = %s, damage_{1} = %s WHERE clan=%s".format("shot_" + str(i), "damage_" + str(i))
cur.execute(sql, (shot, damage, clanname,))
Hope that helps. 希望能有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.