我有一个mysqli_result对象执行此操作:
$mysqli->real_query("SELECT * FROM users WHERE `level` > 2");
$user_list = $mysqli->use_result();
print_r($user_list); die();
这样做,print_r给我:
mysqli_result Object ( [current_field] => 0 [field_count] => 6 [lengths] => [num_rows] => 0 [type] => 1 )
稍后我只是使用while ($row = $user_list->fetch_assoc())
来解析所有内容。想想在做之前我想从mysqli_result对象中检索num_rows
但只做$ user_list ['num_rows']不起作用:
致命错误:无法使用mysqli_result类型的对象作为数组
答案 0 :(得分:2)
$user_list->num_rows
是否有效?
答案 1 :(得分:1)
您必须使用num_rows
$result->num_rows
if ($result = $mysqli->query("")) {
/* determine number of rows result set */
$row_cnt = $result->num_rows;
}
获得num_rows
后,您可以获取它。
答案 2 :(得分:1)
试试这个,在我的情况下它可以工作:)
$query = "SELECT * FROM users WHERE `level` > 2";
$result = mysqli_query($connection, $query);
while ($rows = mysqli_fetch_array($result, MYSQLI_NUM)) {
var_dump($rows);
}
答案 3 :(得分:0)
$mysqli->real_query("SELECT * FROM users WHERE `level` > 2");
$user_list = $mysqli->use_result();
echo $user_list->num_rows;