【发布时间】:2017-11-17 09:01:59
【问题描述】:
当我尝试通过 SQL 将 Python 代码中收集的一些值插入到我的数据库中时,我在以下 Python 代码中遇到 SQL 错误。我收到以粗体突出显示的代码的 SQL 错误。任何帮助表示赞赏!
def add_ingredients(cursor) :
while True:
ingredient = raw_input("Name of ingredient (q to quit):")
if ingredient.lower() !='q':
num = raw_input("Number in storage: ")
description = raw_input("description: ")
sql = '''insert into ingredients
(title, amount, description)
values
**(:title, :amount, :description)'''**
cursor.execute(sql,
{"title":ingredient, "amount":num, "description":description})
print "Added!"
else:
print "Okay, quitting."
break
【问题讨论】:
-
mysql.connector.errors.ProgrammingError: 1064: 你的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 4 行的 ':title, :amount,'':description)' 附近使用正确的语法
-
您应该在问题中说明这一点,并命名您用于连接的库。但是是什么让您认为它接受这种格式的命名参数?
-
请不要尝试将查询的错误部分加粗,并按原样显示您的查询。
标签: python mysql sql python-2.7 insert-into