使用IN子句的PHP PDO预处理语句不起作用

时间:2016-06-07 23:48:36

标签: php mysql pdo

命令行上的以下SQL工作正常:

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

结果:

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

注意$tags是一个数组,如下所示:

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);

结果:

Array ( )

我做错了什么?

0 个答案:

没有答案