進出口使用像這樣使用的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