2011-09-20 39 views
0

我有一個Mysql Update的奇怪問題,我不確定是什麼導致它。我懷疑表本身有問題,但導致錯誤的字段似乎與表中的其他字段相同。我可以在SQL選項卡和php代碼中重新創建phpMyAdmin中的錯誤。我完全難倒了。 在表中的字段定義如下:更新過程中的Mysql語法錯誤,但代碼看起來不錯

bnumber is INT length=11 
bname is VARCHAR length=60 Collation=latin1_swedish_ci 
twittername is VARCHAR length=15 Collation=latin1_swedish_ci 
desc is VARCHAR length=60 Collation=latin1_swedish_ci 

此更新語句的工作原理:

update tbl1 set bname='myName', twittername='myTweet' where bnumber=1; 

這個人給我的錯誤:

update tbl1 set bname='myName', twittername='myTweet', desc='test' where bnumber=1; 

我得到的錯誤是:

#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 'desc='Main' where bnumber=1' at line 1. 

我似乎沒有任何問題從表格中選擇或插入表格。只有更新是給我的錯誤。

我很感激任何幫助。

謝謝!

+1

嘗試在'desc'附近反引號,你知道'desc'是'describe'的關鍵字和同義詞,對不對? –

+0

desc是一個保留字。你需要逃避它。 –

+0

@injekt:它也不是DESCENDING的同義詞嗎? – Mr47

回答

2

desc是一個關鍵字。用反引號逃脫它。

update tbl1 
    set bname='myName', 
     twittername='myTweet', 
     `desc`='test' 
    where bnumber=1; 
3

desc是MySQL中的保留字。你必須反引用它。

+0

嗨,不,我不知道desc是一個關鍵詞。謝謝! – James

0

您不能使用desc作爲字段名稱。 將fieldname更改爲desc1並嘗試。

遞減爲oder by name desc

+0

您可以使用DESC作爲字段名稱,只需在使用時轉義即可。 – CristiC

相關問題