私は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 tho '$ ing_string'を配列に変更する必要があります –
これは私が使い終わった解決策です。ありがとう – pdizz