PreparedStatement fetch_assoc()不返回任何内容

时间:2019-07-06 13:59:40

标签: php mysql

我正在尝试使用PreparedStatements和fetch_assoc()获得x数量的数据数组。它不返回任何东西。这是代码:

if(isset($query_published) && isset($query_date) && isset($query_sort) && isset($query_rows)){
//Does meet the requirements

    $stmt = $db -> prepare("SELECT source, title, timeadded, tags, filed, added, priority, timepublished 
                                        FROM news_archive WHERE ? AND ? ORDER BY ? LIMIT ?");
    $stmt -> bind_param('sssi', $query_date, $query_published, $query_sort, $query_rows);
    //is valid, It's String, String, String, and an Integer.

    $stmt -> execute();
    $result = $stmt -> get_result();

    while($row = $result -> fetch_assoc()){
        //Doesn't run this loop at all.
        $return .= "<tr>";
        $return .= "<td>" . $row["source"] . "</td>";
        $return .= "<td>" . $row["title"] . "</td>";
        $return .= "<td>" . $row["timeadded"] . "</td>";
        $return .= "<td>" . $row["timepublished"] . "</td>";
        $return .= "<td>" . $row["filed"] . "</td>";
        $return .= "</tr>";
        }
    $db -> close();

    }

我已经证实这不是MySQL问题,因为我可以正常运行常规查询。我尝试在执行之前打印出诸如$query_date, $query_published, $query_sort, $query_rows之类的参数,它们是合法值。

查询也很好。我用参数填充了问号,然后在MySQL上运行它,这是一个有效的查询。

0 个答案:

没有答案