PDO IN() Array Statement AND a placeholder

前端 未结 5 870
死守一世寂寞
死守一世寂寞 2021-01-04 08:16

I found this code on SO, which is great for using PDO and the IN() statement together.

$values = explode(\',\', $values) ; # 1,4,7

$placeholders = rtrim(str         


        
5条回答
  •  -上瘾入骨i
    2021-01-04 09:17

    You forgot to prepare it ^_^

    $query = "SELECT * FROM table WHERE id IN ($placeholders) AND product=?";
    $stm = $db->prepare($query) ;
    $stm->execute($values,$product) ; //p00f
    

    And aside from that execute() should only have one parameter

    So the above won't work AT ALL!

    See the DOCs

提交回复
热议问题