PDO SELECT [和 - 或]

时间:2014-02-25 16:38:09

标签: php mysql sql pdo

我有一张桌子:产品

---- id ---- send ---- get ----

---- 1 ----- jack ----- sedo ----

---- 2 ----- jack ----- imam ----

---- 3 ----- imam ----- sedo ----

---- 4 ----- imam----- jack----

我想从PDO PREPARE产品中选择

where (send = imam AND get = jack) OR (send = jack AND get = imam)

这似乎根本不起作用。

$query=$db->prepare("SELECT * FROM product WHERE (send = :send AND get = :get) OR (get = :get AND send = :send)");
$query->execute(array(
    ':send'         => "imam",
    ':get'          => "jack",
    ':send'         => "jack",
    ':get'          => "imam",
    )
);

我该怎么做这个查询?感谢

1 个答案:

答案 0 :(得分:2)

尝试重命名你的参数

$query=$db->prepare("SELECT * FROM product WHERE (send = :send1 AND get = :get1) OR (get = :get2 AND send = :send2)");
$query->execute(array(
    ':send1'         => "imam",
    ':get1'          => "jack",
    ':send2'         => "jack",
    ':get2'          => "imam",
    )
);