2015-05-09 183 views
0

我想通过PHP使用“ON DUPLICATE KEY”查询。这是它看起来像MySQL ON重复密钥语法错误

INSERT INTO `application`.`invites` (`from`, `to`) VALUES ('123', '321') ON DUPLICATE KEY UPDATE `from`=VALUES(from), `to`=VALUES(to) 

我做错了什么?

#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 'from), `to`=VALUES(to)' at line 1 

回答

1

你需要反引号周围fromto,到处都使用它们:

INSERT INTO `application`.`invites` (`from`, `to`) 
    VALUES ('123', '321') 
    ON DUPLICATE KEY UPDATE `from` = VALUES(`from`), `to` = VALUES(`to`) 

其实,这些都是列非常糟糕的名字。您应该避免使用保留字作为列名。