0
我是PDO和準備語句的新手。爲什麼這項工作:試圖找出PHP PDO準備好的語句和佔位符。佔位符在MySQL語句的「IN」子句中
$sth = $dbh->prepare("SELECT *
FROM skyrim_ingredients
WHERE ing_name
IN ('blue butterfly wing', 'blue dartwing', 'blue mountain flower');");
while($row = $sth->fetch()) {
echo $row['ing_id'];
}
...但是這並不:
$ing_string = 'blue butterfly wing', 'blue dartwing', 'blue mountain flower';
$sth = $dbh->prepare("SELECT *
FROM skyrim_ingredients
WHERE ing_name
IN (?);");
$sth->bindParam(1, $ing_string);
$sth->execute();
while($row = $sth->fetch()) {
echo $row['ing_id'];
}
我讀了你的表或列不能使用參數,這與IN子句的情況下,也?
你應該參考這個答案,它說明您的具體問題,http://stackoverflow.com/questions/920353/php-pdo-can-i-bind-an-array-to-an-in-condition壽您需要將'$ ing_string'更改爲數組 – 2012-04-19 04:30:41
這是我最終使用的解決方案。謝謝 – pdizz 2012-04-19 16:48:59