2016-05-30 45 views
0

我正在Python的叽叽喳喳应用程序,我想更新我的数据库中的用户记录。我可以插入不错,但更新提供了以下错误:Mysql连接器错误1064 - 更新与URL

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 

下面是我使用的更新代码:

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,它执行更新没有任何错误。 任何人都可以看到这个解决方案吗?

+0

了解预准备语句 – Jens

+0

您是如何打印SQL查询的?我不认为,他们是一样的。 – qvpham

回答

1

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

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

...", profile_image_url='" + all_data['user']['profile_image_url'] + "' WHERE user_id="... 
+0

是的,它只是缺少引号,谢谢指出。我会看看准备好的陈述 –