命令行上的以下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 ( )
我做错了什么?