进出口使用像这样使用的PDOPDO和SQL陈述
$states = "'SC','SD'";
$sql = "select * from mytable where states in (:states)";
$params = array(':states'=>$states);
,我用我的功能搜索续集
$result = $this->selectArrayAssoc($sql, $params);
在我的selectArrayAssoc功能如下
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;
}
}
它并不需要引用的变量,我认为它在这种情况下会抑制如何处理这个问题。
看到http://stackoverflow.com/questions/920353/php-pdo-can-i-bind-an-array-to-an-in-condition – 2010-04-21 08:25:02