簡體   English   中英

PHP-> MYSQL查詢無法弄清楚出什么錯誤了#1064

[英]php -> MYSQL query can't figure out what is wrong getting error #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(第1行的'User Authenticated','User admin su')

但是,當我使用PHPMYAdmin運行插入時,它確實插入了一個值,並且生成的查詢是

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

我看到的唯一區別是我不認為需要的引號。 我不明白我要去哪里錯了,現在正在傷腦筋:) :)

desc周圍需要反引號,因為它是保留字

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

如果不確定其他列名是否為保留字,則在其他列名周圍添加反引號也不會有任何危害。

這是保留的單詞列表,需要反引號: http : //dev.mysql.com/doc/refman/5.5/en/reserved-words.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM