0

I want to run a following sql query in my php code:SELECT * FROM table1 WHERE id IN (5,6)where the ids inside brackets should be variables content. This query executes properly when I try it on phpmyadmin, however it returns only 1 element when I execute it using this code:

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

The $ids is equal "5,6" and the query seems to be created successfully. Why does it happen?

Mickaël Leger
  • 3,426
  • 2
  • 17
  • 36
gogolon
  • 89
  • 4
  • 10

0 Answers0