I have a table with a unique constraint on two columns. I’m trying to user on duplicate key update but am getting an error…
… create the table
CREATE TABLE IF NOT EXISTS `requests` (
`userFrom` int(11) NOT NULL,
`userTo` int(11) NOT NULL,
`dateSent` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
UNIQUE KEY `userFrom` (`userFrom`,`userTo`)
)
… add some data
INSERT INTO requests (userFrom, userTo) VALUES (1, 2)
… then this fails (when passed userFrom of 1 and userTo of 2
INSERT INTO requests (userFrom, userTo) VALUES (:userFrom, :userTo) ON DUPLICATE KEY UPDATE set dateSent = NOW()
Error is:
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 'set dateSent = NOW()' at line 1
i think there is no needed for
setkeyword here, try this