我希望能够从数据库中删除多个用户,但是下面的代码在某些时候会失败。发生的情况是只有最后点击的用户(即数组$userIds中的最后一个元素)被删除。
我究竟做错了什么?
来自 UserModel.php:
public function RemoveUser(Array $userIds) {
$query = 'DELETE FROM Users WHERE id IN (?)';
$stmt = $this->m_db->Prepare($query);
foreach ($userIds as $value) {
$stmt->bind_param('s', $value);
}
$ret = $this->m_db->DeleteUsers($stmt);
$stmt->Close();
return $ret;
}
来自 Database.php:
public function DeleteUsers(\mysqli_stmt $stmt) {
if ($stmt === FALSE) {
throw new \Exception($this->mysqli->error);
}
if ($stmt->execute() == FALSE) {
throw new \Exception($this->mysqli->error);
}
if ($stmt->fetch()) {
return true;
} else {
return false;
}
}