表:关键字(id,term)
表:ob_key(id,user_id,key_id)
(ob_key.key_id)引用(key.id)
我想基于(ob_key.user_id)和关键字(term)删除(ob_key.id),所以在下面创建一个select语句,但它不起作用
<?php
$term=strtolower($_POST['term']);
$user_id=$_POST['users_id'];
$stmt=$db->prepare("DELETE FROM ob_key WHERE user_id=:user_id AND key_id=(SELECT id FROM keyword WHERE term=:term)");
$stmt->bindParam(":user_id",$user_id);
$stmt->bindParam(":term",$term);
$stmt->execute();
?>
答案 0 :(得分:1)
编辑:
$stmt=$db->prepare("DELETE FROM ob_key WHERE user_id=:user_id AND key_id IN (SELECT id FROM keyword WHERE term=':term')");
问题是我们必须使用IN而不是equals(=)