2011-11-03 139 views
2

我试图在表中插入一些值查询低于:PHP - > MySQL查询无法弄清楚什么是错得到错误#1064

Insert into 
auditlog (
      event, 
      desc, 
      userid, 
      useripaddress, 
      audittype 
) 
VALUES (
     'User Authenticated', 
     'Useradminsuccessfully logged in to the system', 
     '1', 
     '127.0.0.1','1' 
) 

它给了我下面的错误: #1064 - 你的SQL语法错误;检查与您的MySQL服务器版本相对应的手册,以便在'desc,userid,useripaddress,audittype'附近使用正确的语法。VALUES('User Authenticated','User admin su'at line 1

但是,插入使用phpMyAdmin它插入值和生成的查询是

INSERT INTO 
    `auditlog`(
       `event`, 
       `desc`, 
       `userid`, 
       `useripaddress`, 
       `audittype`) 
    VALUES (
       'User Authenticated', 
       'Useradminsuccessfully logged in to the system', 
       '1', 
       '127.0.0.1','1' 
    ) 

我看到的唯一的区别是,我不相信需要加引号,我不明白我要去哪里错了,我打破我的头现在:) :)

+0

的可能重复(HTTP :/ /问题10706920/how-can-i-write-sql-for-a-table-that-shares-the-same-name-as-a-protected-keyword) – Jocelyn

回答

4

反引号需要在desc左右,因为它是reserved word

INSERT INTO auditlog (event, `desc`, userid, useripaddress, audittype) 
VALUES (
    'User Authenticated', 
    'Useradminsuccessfully logged in to the system', 
    '1', 
    '127.0.0.1', 
    '1' 
) 

也有在周围的其他列名加入反引号,如果你不知道他们是否是保留字没有坏处。

+0

明白了.. .thnx ...现在可以使用了! ahah没有想到desc也可以是降序..我想使用短名称来描述...我只是将列名更改为描述以避免任何进一步的问题。谢谢!! –

相关问题