我有一组身份证在饼干里。
当我打印cookie数组时,它会像这样打印:
["39","580"]。我需要访问id39580
我已经尝试了在这样的查询中使用它所需的一切:

    $queryordenar = $db->prepare("SELECT id FROM property
    WHERE id IN (:list) ORDER BY price ASC");
    $queryordenar->execute(array(
    'list' => $array
     ));

谢谢

最佳答案

不能将数组作为参数传递。你需要爆炸阵列,传一个?对于每个值,然后将正确的值绑定到每个占位符:

$bindPlaceholders = [];
foreach ($array as $val) {
    $bindPlaceholders[] = "?";
}
$bindString = "(".implode(",", $bindPlaceholders).")";
$queryordenar = $db->prepare("SELECT id FROM property WHERE id IN ".$bindString." ORDER BY price ASC");
foreach ($array as $i => $val) {
    $queryordenar->bindValue($i + 1, $val); // binding starts at 1
}
$queryordenar->execute();

关于php - Cookie中的数组,使用PDO查询访问,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45718942/

10-09 15:21