2008-11-04 89 views
3

毫無疑問,我的思念很簡單的東西在這裏,但我看不出這個問題與此查詢其產生以下錯誤:簡單的MySQL INSERT錯誤

SQL query: 

INSERT INTO ads(
    ad_id, author, ad_date, category, title, 
    description, condition, price, fullname, 
    telephone, email, status, photo, photothumb 
) 
VALUES (
    NULL , 'justal', '1225790938', 'Windsurf Boards', 
    'test', 'test', 'Excellent', '12', 'test', 
    'test', 'test', '', '', '' 
); 

MySQL said: Documentation 
#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 ''ad_id', 'author', 
'ad_date', 'category', 'title', 'description', 
'condition', '' at line 1 

有人可以用新鮮的對眼睛發現問題?

謝謝, 鋁。

回答

3

不應該在列名中使用反向標記而不是單引號?

INSERT INTO ads(`ad_id`, `author`, `ad_date`, `category`, `title`, `description`, `condition`, `price`, `fullname`, `telephone`, `email`, `status`, `photo`, `photothumb`) 
VALUES (
NULL , 'justal', '1225790938', 'Windsurf Boards', 'test', 'test', 'Excellent', '12', 'test', 'test', 'test', '', '', '' 
); 
+0

是的,但沒有使用引號的都是eassier讀取(如果你的列名是這樣的,你需要說出來了,你選擇錯誤的列名) – 2008-11-04 10:01:08

+1

我完全不同意。在任何時候使用反引號都非常適合可讀性,並且當完美名稱是「關鍵」,「值」等時,您不必爲字段組成任意名稱。 – nickf 2008-11-04 10:03:14

1

單引號用於字符串文字。在MySQL中,默認情況下,雙引號也用於字符串文字,儘管這與標準SQL不兼容,您應該在代碼中使用單引號。

對於列名,您通常不會引用它們。如果你需要 - 而且你不需要 - 然後用反引號(`)引用它們,或者將它設置爲嚴格的ANSI兼容模式(ANSI_QUOTES)並使用雙引號。