Mysql连接器错误1064 - 使用URL更新

时间:2016-05-30 10:38:45

标签: python mysql mysql-connector

我正在使用python中的twitter应用程序,我正在尝试更新数据库中的用户记录。我可以插入正常但更新会出现以下错误:

mysql.connector.errors.ProgrammingError: 1064: 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 '://pbs.twimg.com/profile_images/
735726715267679398/m%HAWxt7_normal.jpg WHERE use' at line 1

以下是我用于UPDATE的代码:

cursor.execute("UPDATE user_table SET following='" + 
str(all_data['user']['following']) + "', followers_count=" + 
str(all_data['user']['followers_count']) + ", favourites_count=" + 
str(all_data['user']['favourites_count']) + ", friends_count=" + 
str(all_data['user']['friends_count']) + ", statuses_count=" + 
str(all_data['user']['statuses_count']) + ", verified=" + 
str(all_data['user']['verified']) + ", profile_image_url=" + 
all_data['user']['profile_image_url'] + " WHERE user_id=" + 
str(all_data['user']['id']))

然后我将SQL打印到下面的屏幕:

UPDATE user_table SET following='None', followers_count=252, 
favourites_count=3899, friends_count=12, statuses_count=506, 
verified=False, profile_image_url='http://pbs.twimg.com/profile_images
/735726715267679398/m%HAWxt7_normal.jpg' WHERE user_id=2933205672

我已将此SQL粘贴到phpmyadmin并运行SQL,并且它执行了更新而没有任何错误。 任何人都可以看到解决方案吗?

1 个答案:

答案 0 :(得分:1)

Jens对准备好的陈述是正确的。这不仅难以调试,而且还存在安全风险。您对SQL注入有所了解。

无论如何,我认为你的问题是缺少引号。

...", profile_image_url='" + all_data['user']['profile_image_url'] + "' WHERE user_id="...
相关问题