我正在尝试使用mysql 5.1和python 2.6.6,我收到以下错误。 代码:
query = "INSERT INTO present_list SET from='a', to='b'"
print query
cur.execute(query)
错误:
Error 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 'from='a', to='b'' at line 1
有人能理解错误吗?
答案 0 :(得分:2)
您需要在from和to中使用仰泳:
INSERT INTO present_list SET `from`='a', `to`='b
因为from是mysql中的关键字
答案 1 :(得分:2)
之前进行反击。 From
是MySQL的reserved words
query = "INSERT INTO present_list (`from`, `to`) VALUES ('a', 'b')"
print query
cur.execute(query)
答案 2 :(得分:1)
Please, learn SQL and Syntex then work on :
Your answer is:
For Insert Data into table
============================
query = "INSERT INTO present_list(from,to) values('a'.'b')";
print query
cur.execute(query)
For Update Data into table
============================
query = "Update present_list set from='a', to='b'";
print query
cur.execute(query)
答案 3 :(得分:0)
from
和to
是mysql保留字。因此,如果您想将它们用作普通名称,请在保留字周围使用反引号(`)符号。欲了解更多信息,请转到
Select a column with a keyword name