When using delete from XXX where id in (XXX) for batch deletion, when using PDO preprocessing, only one record can be deleted at a time. The code is as follows:
<?php
require_once 'conn.php';
$items=$_POST['item'];
$itemsString=implode(",",$items);
$sql=$db->prepare("delete from tb_affiche where id in(?)");
$sql->bindParam(1, $itemsString);
$sql->execute();
?>
It can run normally without preprocessing and delete multiple records in batches. The code is as follows:
<?php
require_once 'conn.php';
$items=$_POST['item'];
$itemsString=implode(",",$items);
$sql=$db->exec("delete from tb_affiche where id in($itemsString)");
?>
I don’t know what went wrong, please help me solve it
Put () into bindParam and take a look