Does anyone know if it's possible to use prepared statements with the IN clause in PDO (or any engine for that matter)?

What I would like to be able to do is something like the following.

// $db is a PDO object
$stmt = $db->prepare("SELECT * FROM mytable WHERE id IN (?)");
$stmt->execute(
  array( // Array of parameters
    array( 1, 2, 3, 4, 5) // Parameter as an array because IN can have multiple terms
  )
);

Unfortunately this doesn't work.

Ayone got any ideas?

Cheers
Rob

    It cannot be done with PDO, according to the PHP Manual's entry on PDO::prepare(), which says:
    "You cannot bind multiple values to a single named parameter in, for example, the IN() clause of an SQL statement."

      5 days later

      Oh yea. I completely missed that.

      Thanks
      laserlight

        Write a Reply...