准备好的语句WHERE IN子句表现出意外

时间:2017-05-07 18:07:53

标签: php mysql mysqli prepared-statement

好的,我正在重写一些旧的查询,但WHERE IN子句的工作方式与我以前的旧SQL一样吗?它基本上只从被检查的变量

中取“1”
    $checked = "1,2,3";

新准备的声明

    $stmt = $dbCon->prepare("SELECT id FROM rating WHERE category IN (?)");
    $stmt->bind_param('s', $checked);
    $stmt->execute();
    $stmt->bind_result($id);
    $randomArr;
    while($stmt->fetch()){
        echo $id . "<br>";
    }
    echo "<br><br>";

旧查询有效

    $sql = "SELECT id FROM rating WHERE category IN ($checked)";
    $result_user_stemmer = $dbCon->query($sql);
    $arr_alle_billeder;
    while ($obj = $result_user_stemmer->fetch_object()) {
        // for hver user_source billedet IKKE skal vises
        echo $obj->id . "<br>";
    }

示例输出链接here

0 个答案:

没有答案