PDO and SQL IN statements
Posted
by Sai
on Stack Overflow
See other posts from Stack Overflow
or by Sai
Published on 2010-04-21T08:19:51Z
Indexed on
2010/04/21
8:23 UTC
Read the original article
Hit count: 421
Im using a sequel for search like this using PDOs
$states = "'SC','SD'";
$sql = "select * from mytable where states in (:states)";
$params = array(':states'=>$states);
and I use my function
$result = $this->selectArrayAssoc($sql, $params);
where my selectArrayAssoc function as following
public function selectArrayAssoc($sql, $params = array()){
try{
$sth = $this->db->prepare($sql);
$sth->execute($params);
$result = $sth->setFetchMode(PDO::FETCH_ASSOC);
return $sth->fetchAll();
}catch(PDOException $e){
print $e->getMessage();
//Log this to a file later when in production
exit;
}
}
it does not take the quoted variables, I think it is suppressing, in such cases how to deal with this.
© Stack Overflow or respective owner