有一个无法正常工作的删除方法......任何人都可以找出它返回0
的原因吗?该项目存在于表格中。
public function deleteItem($item_id)
{
$userItemIDS = array();
$userItemIDS = $this->helperClass->userItemIDS();
if( !in_array($item_id, $userItemIDS) )
{
return false;
}
$q = $this->db->mysqli->prepare("DELETE i, s FROM items i
LEFT JOIN save_list s
ON i.id = s.item_id
WHERE i.id = ? AND s.item_id = ?
AND
NOT EXISTS (SELECT id FROM pending_wins WHERE item_id = ?)
AND
NOT EXISTS (SELECT id FROM bids WHERE item_id = ?)");
if($q)
{
$q->bind_param("iiii", $item_id, $item_id, $item_id, $item_id);
$a_r = $q->affected_rows;
$q->execute();
$q->close();
return $a_r;
}
}
答案 0 :(得分:0)
评论非常有帮助,我非常感谢他们。但是我的问题出在查询本身。取出AND s.item_id = ?
会删除
来自items
表和save_list
(如果有)的条目。
$q = $this->db->mysqli->prepare("DELETE i, s FROM items i
LEFT JOIN save_list s
ON i.id = s.item_id
WHERE i.id = ?
AND
NOT EXISTS (SELECT id FROM pending_wins WHERE item_id = ?)
AND
NOT EXISTS (SELECT id FROM bids WHERE item_id = ?)");