Bonjour,
Je souhaite utiliser une requête préparée avec la commande DELETE pour supprimer des données grâce à un tableau d'entiers (des identifiants).
Ces identifiants sont récupérés au format JSON.
Voici la structure de la table où je souhaite faire ma requête :
J'ai commencé par un premier code qui fonctionne :
Mais je préfère faire ça un peu plus proprement comme ceci :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 <?php require_once('connexiondb.php'); $json = file_get_contents('php://input'); $arrayTopicIds = json_decode($json); $stmt = $db->prepare('DELETE FROM topicspe WHERE topicpe_id IN ('.implode(',', array_map('intval', $arrayTopicIds)).')'); $stmt->execute(); $stmt->closeCursor(); ?>
Mais le message suivant apparaît :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 <?php require_once('connexiondb.php'); $json = file_get_contents('php://input'); $arrayTopicIds = json_decode($json); $topicsIds = implode(',', array_map('intval', $arrayTopicIds)); $stmt = $db->prepare('DELETE FROM topicspe WHERE topicpe_id IN (:ids)'); $stmt->bindParam(':ids', $topicsIds); $stmt->execute(); $stmt->closeCursor(); ?>
SQLSTATE[22007]: Invalid datetime format: 1292 Truncated incorrect DOUBLE value: '13,14'
Qu'aurais-je oublié ?
En vous remerciant pour votre aide.
Partager