2012-11-30 114 views
1

我想用python 2.6.6來使用mysql 5.1,並且出現以下錯誤。 代碼:錯誤1064在python中使用mysql

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 

有人可以明白什麼是錯的?

回答

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) 
2

您需要使用仰泳,從和喜歡:

INSERT INTO present_list SET `from`='a', `to`='b 

由於是從MySQL中的關鍵字

+0

Thx,它現在工作! – billx

+0

@ user1865939您不可錯過 –

2

從之前把背擊。 From是MySQL的reserved words

query = "INSERT INTO present_list (`from`, `to`) VALUES ('a', 'b')" 
print query 
cur.execute(query) 
+0

Thx,它現在正在工作! – billx

0

fromto是MySQL的保留字之一。所以,如果你想使用它們作爲普通名稱,請在保留字周圍使用反引號(`)符號。欲瞭解更多信息,請轉到 Select a column with a keyword name