Is there y in x IDs with PDO

Hello,

In the satellite table, does anybody have a type of MDU in 1,2,3 IDs?

I tried to do it from here but it didn’t work: https://phpdelusions.net/pdo

$arr = [1,2,3];
$in  = str_repeat('?,', count($arr) - 1) . '?';
$sql = "SELECT * FROM satelite WHERE lnb_type=:lnb_type AND id IN ($in)";
$stm = $pdo->prepare($sql);
$params = array_merge(['lnb_type' => 'MDU'], $arr);
$stm->execute($params);
$data = $stm->fetchAll();

Is there only? 0 or 1

You cannot mix named :some_name and positional ? place-holders in one query.

$arr = [1,2,3];
$in  = str_repeat('?,', count($arr) - 1) . '?';
$sql = "SELECT * FROM satelite WHERE lnb_type=? AND id IN ($in)";
$stm = $pdo->prepare($sql);
$params = array_merge(['MDU'], $arr);
$stm->execute($params);
$data = $stm->fetchAll();

Yes it worked like this
Thank you

How do I get it if it is present or not?
0 or 1

It worked this way. result: 0-1

    $arr = [1,2,3];
    $in  = str_repeat('?,', count($arr) - 1) . '?';
    $sql = "SELECT * FROM satelite WHERE lnb_type=? AND id IN ($in)";
    $stm = $PDOdb->prepare($sql);
    $params = array_merge(['MDU'], $arr);
    $stm->execute($params);
    $userExists = $stm->rowCount();
Sponsor our Newsletter | Privacy Policy | Terms of Service