Why not bindata parameters PDO?

Hello!

At $art_string on data: string(10) "963,963,70"

I'm trying to select from the table only article IDs that correspond to those of the $art_string:

$stm = $pdo->prepare('SELECT `id` FROM `article` WHERE id=:id');
 $stm->bindParam(':id', $art_string, PDO::PARAM_INT);
 $art_id = $stm->fetchAll();


Returns an empty array:

echo "<pre>";
var_dump($art_id);
echo "</pre>";

array(0) {
}

Although in the article there is a table id that match the data from $art_string.

What could be the problem?
Thank you.
July 2nd 19 at 17:22
3 answers
July 2nd 19 at 17:24
Solution
I was looking to see what query goes to database?
Because you initially request written incorrectly. You pass the parameters separated by commas. In one condition. Of course it won't find the ID like this: 963,963,70.
In General, Yes. And like errors shouldn't be. In any case, the returned array should not be empty - viva_Veum commented on July 2nd 19 at 17:27
: the parameters in the query go like this: 963,963,70? - fredrick6 commented on July 2nd 19 at 17:30
Yes Yes - viva_Veum commented on July 2nd 19 at 17:33
WHERE `id` IN ('1', '2', '3', '4', '5') - fredrick6 commented on July 2nd 19 at 17:36
: Yes, all right. Conclusion is possible only IN operator - viva_Veum commented on July 2nd 19 at 17:39
July 2nd 19 at 17:26
Use IN

$ids = [963, 963, 70];
$inQuery = implode(',', array_fill(0, count($ids), '?'));

$stmt = $db->prepare('
SELECT `id` FROM `article` WHERE id IN(' . $inQuery . ')
');

foreach ($ids as $k => $id)
 $stmt->bindValue(($k+1), $id, \PDO::PARAM_INT);

$stmt->execute();
$allResult = $stmt->fetchAll();
July 2nd 19 at 17:28
need execute to make

Find more questions by tags PHPPHP PDO