I've seen similar posts but none of the answers helped me... I have this table:
CREATE TABLE IF NOT EXISTS `user_likes_name` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`id_user` int(11) NOT NULL,
`id_name` int(11) NOT NULL,
`like` enum('yes','no','ask_later') NOT NULL,
`date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`provenance` enum('elimination','selection','suggestion') NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `avis_user` (`id_user`,`id_name`),
KEY `id_user` (`id_user`,`id_name`)
)
And I use this query:
INSERT INTO user_likes_name (id_user, id_name, `like`)
VALUES (?, ?, 'ask_later')
ON DUPLICATE KEY UPDATE `date` = current_timestamp
Which works fine on phpmyadmin.
But when I use it in my code (with PDO) I get this error message:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicata du champ '99-869' pour la clef 'avis_user'' in C:\fakepath.php on line 95
My PHP code is:
$req = $bdd->prepare("
INSERT INTO user_likes_name (id_user, id_name, `like`)
VALUES (?, ?, 'ask_later')
ON DUPLICATE KEY UPDATE `date` = current_timestamp");
$req->execute(array($foo, $bar));
I feel like I'm going kwayzey. Am I?
Two hours of work later, I realized I wasn't actually working on the right file. It's hard to overstate the way I'm feeling jaded right now.