首页 > 解决方案 > 如何修复非对象错误的属性“num_rows”

问题描述

  if ($result-> num_rows > 0) {                
   while($row = $result->fetch_assoc()) {
     code here..}`

以上是我的 php 代码,但服务器总是说下面的错误。

试图在...中获取非对象的属性“num_rows”

标签: phpmysqli

解决方案


试试这个>

$result = $conn->query($sql);
if($result){
  if ($result->num_rows > 0) {                
   while($row = $result->fetch_assoc()) {
     code here..}`
}

推荐阅读