我正在使用下面的 MYSQL 查询从表中删除单个记录,并且对我来说工作完美,但如何使用 IN 运算符编写多个记录。
$sql = "DELETE FROM reg WHERE id = :id";
$query = $this->db->prepare($sql);
$query->execute(array(':id' => $id));
例如,我有像 $id = array(23,24);
这样的数组中的 id,并且我有像下面这样的循环的 treid,但没有工作:(
for($i=0; $i<count($id); $i++) {
$id = $id[$i];
$sql = "DELETE FROM $table_name WHERE id = :$id";
$query = $this->db->prepare($sql);
$query->execute(array(':id' => $id));
}
希望您能理解我的问题并帮助我。
谢谢。
最佳答案
for($i=0; $i<count($id); $i++) {
$sql = "DELETE FROM $table_name WHERE id = :id";
$query = $this->db->prepare($sql);
$query->execute(array(':id' => $id[$i]));
}
关于php - 使用 PHP PDO 扩展删除 MySQL 数据库中的多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23149220/