I am trying to insert some values in the table the query is below:
我试图在下面的查询表中插入一些值:
Insert into
auditlog (
event,
desc,
userid,
useripaddress,
audittype
)
VALUES (
'User Authenticated',
'Useradminsuccessfully logged in to the system',
'1',
'127.0.0.1','1'
)
It gives me the following 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 'desc,userid,useripaddress,audittype)VALUES ('User Authenticated', 'User admin su' at line 1
它给我以下错误:#1064 - 您的SQL语法中有错误;查看与您的MySQL服务器版本对应的手册,以便在'desc,userid,useripaddress,audittype'附近使用正确的语法VALUES('User Authenticated','User admin su'在第1行
However when i run the insert using PHPMYAdmin it does insert a value and the query generated is
但是,当我使用PHPMYAdmin运行插入时,它会插入一个值并生成查询
INSERT INTO
`auditlog`(
`event`,
`desc`,
`userid`,
`useripaddress`,
`audittype`)
VALUES (
'User Authenticated',
'Useradminsuccessfully logged in to the system',
'1',
'127.0.0.1','1'
)
The only difference i see is the quotes which i dont believe are needed. I don't understand where am i going wrong and am breaking my head now :):)
我看到的唯一区别是我不相信需要的报价。我不明白我哪里出错了,现在我的头脑崩溃:) :)
2 个解决方案
#1
4
The backticks are needed around desc
because it is a reserved word.
在desc周围需要反引号,因为它是一个保留字。
INSERT INTO auditlog (event, `desc`, userid, useripaddress, audittype)
VALUES (
'User Authenticated',
'Useradminsuccessfully logged in to the system',
'1',
'127.0.0.1',
'1'
)
There is also no harm in adding backticks around the other column names if you aren't sure whether or not they are reserved words.
如果你不确定它们是否是保留字,那么在其他列名称周围添加反引号也没有坏处。
#2
0
Here is a list of words that are reserved and needs to be backticked: http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html
以下是保留且需要重新添加的单词列表:http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html
#1
4
The backticks are needed around desc
because it is a reserved word.
在desc周围需要反引号,因为它是一个保留字。
INSERT INTO auditlog (event, `desc`, userid, useripaddress, audittype)
VALUES (
'User Authenticated',
'Useradminsuccessfully logged in to the system',
'1',
'127.0.0.1',
'1'
)
There is also no harm in adding backticks around the other column names if you aren't sure whether or not they are reserved words.
如果你不确定它们是否是保留字,那么在其他列名称周围添加反引号也没有坏处。
#2
0
Here is a list of words that are reserved and needs to be backticked: http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html
以下是保留且需要重新添加的单词列表:http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html