【发布时间】:2019-01-28 19:07:12
【问题描述】:
我正在尝试将数据插入到我的 mysql 数据库中,但我总是收到参数有问题的错误,我想将其添加到我的插入语句中,我尝试了各种解决方案和一个's', 's' 工作,它被插入到我的数据库中。
有人知道哪里出了问题吗?
谢谢。
try:
conn = mysql.connect()
cursor = conn.cursor()
insert_cmd = "INSERT INTO TBTAB VALUES(%s, %s, %s, %s, %s)"
#insert_cmd = "INSERT INTO TBTAB VALUES('s', 's', 's', 's', 's')"
# insert_cmd = "INSERT INTO TBTAB VALUES(?, ?, ?, ?, ?)"
tpa= ("szilva", "barack", "meggye", "alma", "korte")
#cursor.execute("INSERT INTO TBTAB (UserName, Email, TextBoxCont, NodeChosen, CurDate) VALUES ('Caal', 'TomErichsen', 'Svanger', '400esd6', 'Nqdwasorway');")
cursor.execute(insert_cmd.format(tpa))
conn.commit()
return render_template('form.html')
except Exception as e:
return str(e)
错误:
(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 '%s, %s, %s, %s, %s)' at line 1")
【问题讨论】:
-
您不应该使用
format将参数插入到您的查询中。试试cursor.execute(insert_cmd, tpa)