$arr=implode(",",$ids);
    //echo $arr;
    $sql = "DELETE FROM student WHERE id IN (?)";
    $st =$pdo->prepare($sql);
    var_dump($st->bindParam(1,$arr,PDO::PARAM_STR));
    $st->execute();
部分代码,请问怎么做批量删除啊,我现在只能删除第一个。

解决方案 »

  1.   

    Looks like PDO ignores the multiples values in IN clause. Solution you can use to overcome this issue could be like below:
      $clause = str_repeat("?,", count($ids)-1) . "?"; 
      $sql = "DELETE FROM student WHERE id IN ($clause)";
      $st =$pdo->prepare($sql);
      $st->execute($ids); 
      

  2.   

    这位朋友,我把你代码拷贝过去运行,成功了,但由于我是初学者,能不能麻烦您给我详细解释下$clause = str_repeat("?,", count($ids)-1) . "?"; 是什么意思?
      

  3.   

    str_repeat — 重复一个字符串http://www.php.net/manual/zh/function.str-repeat.phpstring str_repeat ( string $input , int $multiplier )返回 input 重复 multiplier 次后的结果。 //Ali