mysql中的store_result()和get_result()返回false

时间:2015-01-31 15:42:28

标签: php mysql return prepared-statement

我几天前创建了一个代码,包括get_result()来从我的数据库中收到结果。今天我想加入它并修复一些错误。所以我尝试使用num_rows来查看是否有任何返回。但为此,我不得不使用store_result()。当我这样做时get_result()只返回一个false的布尔值。当我评论store_result()时,一切正常。 我知道>=会搞砸它。但我把=放在那里进行调试(注释掉store_result()并看看发生了什么)。所以这不是问题

$sql = $this->connect();
$a = $sql->prepare("SELECT `name`, `title`, `comment`, `date`  FROM `comment` WHERE `post`=?");
$a->bind_param("s", $id);
$a->execute();
$a->store_result();
if ($a->num_rows >= 0) {
    $res = $a->get_result();
    var_dump($res);

    while ($row = $res->fetch_assoc()) {
        $results[] = $row;
    }
    return $results;
} else {
    return false;
}

1 个答案:

答案 0 :(得分:3)

使用get_result()的{​​{1}} 代替,然后使用结果对象的store_result()

num_rows