几天前,我编写了一个代码,包括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;
}
使用get_result()
替代的store_result()
,然后使用结果对象的num_rows
:
$a->execute();
$res = $a->get_result();
if ($res->num_rows > 0) {
while ($row = $res->fetch_assoc()) {
$results[] = $row;
}
return $results;
} else {
return false;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句