Bonjour,

J'ai une table dat_favourites avec le code SQL suivant:
Code sql : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
CREATE TABLE IF NOT EXISTS `dat_recents` (
  `id_user` int(10) UNSIGNED NOT NULL,
  `id_customer` int(10) UNSIGNED NOT NULL,
  `update_date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  KEY `id_user` (`id_user`),
  KEY `id_customer` (`id_customer`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
INSERT INTO `dat_recents` (`id_user`, `id_customer`, `update_date`) VALUES
(4, 399, '2021-04-14 19:49:54'),
(6, 2950, '2021-06-02 10:04:22'),
(6, 2951, '2021-06-02 09:55:47'),
(6, 2953, '2021-06-02 10:03:52'),
(6, 3010, '2021-06-02 10:03:59'),
(6, 3011, '2021-06-02 10:04:41'),
(7, 1, '2021-06-13 08:09:31'),
(7, 2, '2021-06-13 08:06:17'),
(7, 3, '2021-06-13 08:07:15'),
(7, 5, '2021-06-13 08:05:40'),
(7, 6, '2021-06-13 07:30:32');
 
ALTER TABLE `dat_recents`
  ADD CONSTRAINT `dat_recents_ibfk_1` FOREIGN KEY (`id_customer`) REFERENCES `dat_customers` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `dat_recents_ibfk_2` FOREIGN KEY (`id_user`) REFERENCES `dat_users.old` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
Et la fonction PDO suivante:
Code php : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
function updateLatest($userId, $customerId) {
	$db = dbConnect();
	// By deleting then inserting, the column 'update_date' is automatic updated
	// there are also no duplicate and unused tuples
	var_dump($userId,$customerId); // return 9, 3
 
	$sql = <<<SQL
	DELETE FROM dat_recents
	WHERE id_user=:userId AND id_customer=:customerId
SQL;
	$stmt = $db->prepare($sql);
	$stmt->execute([':userId'=>$userId, ':customerId'=>$customerId]);
 
	$sql = <<<SQL
		INSERT IGNORE INTO dat_recents
		(id_user, id_customer) VALUES(:userId, :customerId)
SQL;
	$stmt = $db->prepare($sql);
	$stmt->execute([':userId'=>$userId, ':customerId'=>$customerId]);
}

Pourquoi le couple 9,3 ne s'enregistre pas?