1. 程式人生 > >凜冬之翼---You have an error in your SQL syntax; check the manual that corresponds to your

凜冬之翼---You have an error in your SQL syntax; check the manual that corresponds to your

今天在寫網頁與資料庫互動的程式碼的時候遇到了一個問題You have an error in your SQL syntax; check the manual that corresponds to your

問題分析:從英文翻譯過來的字面上意思是你的資料庫MySQL出現問題,也就是MySQL的語句有問題,我找了好多辦法,百度過後大概有一下兩種可能:
1.MySQL語句錯誤。如字母打錯,逗號忘記打之類。
2.關鍵字佔用。如time parameter等關鍵字佔用了。
然後我的錯誤是屬於關鍵字沒有加引號,之前的程式碼是:

"INSERT INTO books (name,category,price,publish_l_time) VALUES (?, ?, ?, ?)"
)

這樣子就會報錯。

應該把變數名都加上``號。

INSERT INTO books (`name`,`category`,`price`,`publish_time`) VALUES (?, ?, ?, ?)");

問題解決!