title: PHP - PDO not taking imploded array as question mark parameter for IN clause in SELECT query
body: <p>I have a problem with a question mark parameter in a prepared statement using PDO. My Query class looks like this (<em>for now, I'm still adding functionality like data limits, custom parameters filtering and automatic detection of supported statements for the driver being used</em>):</p>
  
  <pre><code>// SQL query
  class Query {
      public $attributes;
  
      // constructor for this object
      public function __construct() {
          if ($arguments = func_get_args()) {
              $tmp = explode(" ", current($arguments));
  
              if (in_array(mb_strtoupper(current($tmp)), ["ALTER", "DELETE", "DROP", "INSERT", "SELECT", "TRUNCATE", "UPDATE"], true)) {
                  // classify the query type
                  $this-&gt;attributes["type"] = mb_strtoupper(current($tmp));
  
                  // get the query string
                  $this-&gt;attributes["query"] = current($arguments);
  
                  // get the query parameters
                  if (sizeof($arguments) &gt; 1) {
                      $this-&gt;attributes["parameters"] = array_map(function ($input) { return (is_array($input) ? implode(",", $input) : $input); }, array_slice($arguments, 1, sizeof($arguments)));
                  }
  
                  return $this;
              }
          }
      }
  }
  </code></pre>
  
  <p>This is the code fragment which executes the query:</p>
  
  <pre><code>$parameters = (!empty($this-&gt;attributes["queries"][$query]-&gt;attributes["parameters"]) ? $this-&gt;attributes["queries"][$query]-&gt;attributes["parameters"] : null);
  
  if ($query = $this-&gt;attributes["link"]-&gt;prepare($this-&gt;attributes["queries"][$query]-&gt;attributes["query"], [\PDO::ATTR_CURSOR =&gt; \PDO::CURSOR_FWDONLY])) {
      if ($query-&gt;execute((!empty($parameters) ? $parameters : null))) {
          return $query-&gt;fetchAll(\PDO::FETCH_ASSOC);
      }
  }
  </code></pre>
  
  <p>And this is how I call it in my test code:</p>
  
  <pre><code>$c1-&gt;addQuery("lists/product-range", "SELECT * FROM `oc_product` WHERE `product_id` IN (?);", [28, 29, 30, 46, 47]);
  
  if ($products = $c1-&gt;execute("test2")) {
      foreach ($products as $product) {
          print_r($product);
      }
  }
  </code></pre>
  
  <p>The problem I have is I just see the first product (it's a test against a vanilla OpenCart installation) with id 28. As you can see in my code, if the passed parameter is an array, it gets automatically detected by the lambda I have in place in the Query class constructor, so it gets rendered as a string like <code>28,29,30,46,47</code>.</p>
  
  <p>Is there a missing parameter in PDO setup I'm missing? Or maybe there's some bug or platform limit in what I'm doing? I know there's some limitations on what PDO can do in regards to arrays, and that's why I pre-implode all arrays for them to be passed like a simple string.</p>
  
  <p>There's some procedures I've seen here in SO which, basically, composes the query string like <code>WHERE product_id IN ({$marks})</code>, where <code>$marks</code> is being dynamically generated using a procedure like <code>str_repeat("?", sizeof($parameters))</code> but that's not what I'm looking for (I could resort to that in case there's no known alternative, but it doesn't look like a very elegant solution).</p>
  
  <p>My development environment is composed of: Windows 7 x64, PHP 5.4.13 (x86, thread-safe), Apache 2.4.4 (x86) and MySQL 5.6.10 x64.</p>
  
  <p>Any hint would be greatly appreciated :)</p>