在python中插入MySQL数据库时出现问题

2024-05-19 20:00:51 发布

您现在位置:Python中文网/ 问答频道 /正文

当我尝试用python插入数据库时,当前收到以下错误。如果你们能帮我的忙,我将不胜感激。在

        league_Build_Data(1,0,'Infinity Edge, Mobility Boots, Black Clever, Deaths Dance, Essense Reaver, Guardian Angle', 2431, 'Caitlyn, Blitzcrank, Lee Sin, Ahri, Trundle', 'Anivia, Akali, Draven, Nami, Fiddle Sticks', 12, 3, 15, 231)

mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'kill, death, assist, creep_score) VALUES (1, 0, 'Infinity Edge, Mobility Boots, ' at line 1

下面是运行的代码:

^{pr2}$

提前感谢您的帮助!在


Tags: thetobuild数据库yourdata错误clever
2条回答

看着你的SQL错误,我在分解它时注意到:

query = "INSERT INTO league_Build_Data (win, lose, build, game_Length, champions_team, champions_enemy, kill, death, assist, creep_score) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s);"

排得很长。 如果您将上述行更改为

^{pr2}$

删除上述并将行改为:

query = ("INSERT INTO league_Build_Data"
        "(win, lose, build, game_Length, champions_team, champions_enemy, kill, death, assist, creep_score)"
        "VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)")

那么你的SQL应该可以工作了。在

我也建议不要分配w = win等等,只要

value = (win, lose, build, game_Length, champions_team....)

因为你只是在增加额外的行。在

我猜INSET应该是INSERT?此外,查询中有9个%s项,但有10个值(在数据库中似乎有10个列)。在

相关问题 更多 >