[英]Error 1064 using mysql in python
I'm trying to use mysql 5.1 with python 2.6.6 and I'm getting the following error. 我正在尝试将mysql 5.1与python 2.6.6结合使用,并且遇到以下错误。 code :
代码:
query = "INSERT INTO present_list SET from='a', to='b'"
print query
cur.execute(query)
error : 错误:
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
Can somebody understand what is wrong ? 有人可以理解哪里出了问题吗?
You need to use the backstroke in from and to like : 您需要使用from和like的仰泳:
INSERT INTO present_list SET `from`='a', `to`='b
Since from is a keyword in mysql 由于from是mysql中的关键字
Put a back strike before from. 从发动反击。
From
is one of MySQL's reserved words From
是MySQL的保留字之一
query = "INSERT INTO present_list (`from`, `to`) VALUES ('a', 'b')"
print query
cur.execute(query)
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)
from
and to
are mysql reserved words. from
和to
是mysql保留字。 So if you want to use them as normal names please use backtick(`) symbol around reserved word. 因此,如果要使用它们作为普通名称,请在保留字周围使用backtick(`)符号。 For more info please goto Select a column with a keyword name
有关更多信息,请转到选择带有关键字名称的列
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.