Proper format for PDO and MySQL IN/NOT IN queries

后端 未结 1 421
闹比i
闹比i 2020-12-11 11:46

For reasons that should be obvious, this is murder to search for...

How do I do this in PDO:

SELECT thing FROM things WHERE thing_uid IN ( ... )


        
相关标签:
1条回答
  • 2020-12-11 12:02

    Create an array of as many ? as you have values, and throw that into the query.

    $placeholders = array_fill(0, count($thingArray), '?');
    $sql = "SELECT thing FROM things WHERE thing_uid IN (" . implode(',', $placeholders) . ")";
    
    0 讨论(0)
提交回复
热议问题