douxiuyi6529 2019-07-06 13:59
浏览 31

PreparedStatement fetch_assoc()不返回任何内容

I'm trying to get an array of x amount of data using PreparedStatements and fetch_assoc(). It doesn't return anything. Here's the code:

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();

    }

I've verified it's not a MySQL problem, since I can run regular queries just fine. I tried printing out the parameters such as $query_date, $query_published, $query_sort, $query_rows before execution, and they are legitimate values.

The query is fine too. I filled the question marks with the parameters, and ran it on MySQL, is a valid query.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
    • ¥15 关于#hadoop#的问题
    • ¥15 (标签-Python|关键词-socket)
    • ¥15 keil里为什么main.c定义的函数在it.c调用不了
    • ¥50 切换TabTip键盘的输入法
    • ¥15 可否在不同线程中调用封装数据库操作的类