Home  >  Q&A  >  body text

php - delete...in() delete statement preprocessing and non-preprocessing result are different

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

曾经蜡笔没有小新曾经蜡笔没有小新2698 days ago829

reply all(1)I'll reply

  • 高洛峰

    高洛峰2017-05-24 11:34:31

    Put () into bindParam and take a look

    reply
    0
  • Cancelreply