我有以下代码来检查是否存在行然后执行某些操作。但是,我正在
调用成员函数fetch_assoc()
我发现如果我在$check->get_result();
之前放$check->store_result();
这个错误就会消失但是当我这样做并且回显$check->num_rows;
时,我得到空的结果,即使我有一行表。我做错了什么?
var_dump($check_result);
给我以下
0bject(mysqli_result)#6 (5) {
["current_field"]=> int(0)
["field_count"]=> int(25)
["lengths"]=> NULL
["num_rows"]=> int(1)
["type"]=> int(0)
}
这是查询...
$material = '';
$check_added = $mysqli->prepare("select * from table where material = ? order by id desc limit 1");
$check_added->bind_param('s', $material);
$check_added->execute();
$check_result = $check_added->get_result();
$check_added->store_result();
echo $check_added->num_rows;
if($check_added->num_rows < 1)
{
//Do something
}
else
{
while($checkrow = $check_result->fetch_assoc()){
echo $checkrow['title'];
}
答案 0 :(得分:0)
$ check_added是一个mysqli预处理语句对象,你要像结果集一样对待,你有没有treq $ check_result-&gt; num_rows?