参见英文答案 >
PHP – Using PDO with IN clause array2
$statement = $db->prepare('SELECT blah FROM blah_table WHERE blahID IN (:a,:b,:c)');
您可以动态构建“IN(…)”字符串:
原文链接:/php/139758.html$in_string = '('; foreach ( $array_of_parameters as $parameter ) { $in_string .= ':' . chr($i + 97) . ','; // Get the ASCII character } $in_string = substr($in_string,-1) . ')'; $statement = $db->prepare("SELECT blah FROM blah_table WHERE blahID IN ($in_string)");