我想在我的php代码中运行以下sql查询:SELECT * FROM table1 WHERE id IN (5,6)
,其中括号内的id应该是变量内容。当我在phpmyadmin
上尝试该查询时,该查询可以正确执行,但是当我使用以下代码执行该查询时,它仅返回1个元素:
$pdo = new ConnectionDatabase();
$db = $pdo->connect();
$query = $db->prepare("SELECT * FROM table1 WHERE id IN (:ids)");
$ids = "";
foreach($this->getIds() as $matId)
{
$ids .= $matId . ",";
}
$ids = substr_replace($ids, "", -1);
$query->bindParam(':ids', $ids);
$query->execute();
$response = $query->fetchAll(PDO::FETCH_ASSOC);
$ids
等于“ 5,6”,并且查询似乎已成功创建。为什么会发生?