php – 为什么mysqli num_rows总是返回0?
发布时间:2020-12-13 14:06:25  所属栏目:PHP教程  来源:网络整理 
            导读:使用 mysqli获取返回的行数一直很困难.我每次都得到0回,尽管肯定有一些结果. if($stmt = $mysqli-prepare("SELECT id,title,visible,parent_id FROM content WHERE parent_id = ? ORDER BY page_order ASC;")){ $stmt-bind_param('s',$data-id); $stmt-execu
                
                
                
            | 
 使用 
 mysqli获取返回的行数一直很困难.我每次都得到0回,尽管肯定有一些结果. 
  
  
  if($stmt = $mysqli->prepare("SELECT id,title,visible,parent_id FROM content WHERE parent_id = ? ORDER BY page_order ASC;")){  
    $stmt->bind_param('s',$data->id);  
    $stmt->execute();
    $num_of_rows = $stmt->num_rows;  
    $stmt->bind_result($child_id,$child_title,$child_visible,$child_parent);  
    while($stmt->fetch()){
        //code
    }
    echo($num_of_rows);
    $stmt->close();
}为什么不显示正确的数字? 
 您需要在num_rows查找之前调用 
  MySqli_Stmt::store_result():if($stmt = $mysqli->prepare("SELECT id,$data->id);  
    $stmt->execute();
    $stmt->store_result(); <-- This needs to be called here!
    $num_of_rows = $stmt->num_rows;  
    $stmt->bind_result($child_id,$child_parent);  
    while($stmt->fetch()){
        //code
    }
    echo($num_of_rows);
    $stmt->close();
}请参阅the docs on  (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! | 
