0

The following SQL on the command line works fine:

SELECT `id` FROM `tags` WHERE tag IN ("#adventure", "#blub", "#club");

Result:

+----+
| id |
+----+
| 32 |
| 18 |
| 19 |
+----+

Note $tags is an array as follows:

Array
(
    [0] => #adventure
    [1] => #blub
    [2] => #blah
)

PHP PDO:

$tags = '"' . implode('","', $tags) . '"';
$idSql = 'SELECT `id` FROM `tags` WHERE tag IN (:tags)';
$stmt = $this->dbh->prepare($idSql);
$stmt->execute(array(':tags' => $tags));
$result = $stmt->fetchAll();
print_r($result);

Result:

Array ( )

What am I doing wrong?

Robert
  • 10,126
  • 19
  • 78
  • 130
  • use dynamic placeholders – Kevin Jun 07 '16 at 23:52
  • This questions is also a duplicate of: [Can I bind an array to an IN() condition?](http://stackoverflow.com/questions/920353/can-i-bind-an-array-to-an-in-condition) – Jocelyn Jun 07 '16 at 23:56

0 Answers0