注意:未定义的属性:PDOStatement :: $ mysqli_num_rows in

时间:2017-10-03 07:24:34

标签: php

这是我的PHP代码,它返回以下错误。

public static function categoryParentChildTree($parent = 14, $spacing = '', $category_tree_array = '') {

    $db=Db::getConnection();

    if (!is_array($category_tree_array))
        $category_tree_array = array();

    $sql = 'SELECT id,name,parentid FROM category WHERE parentid = 14 ORDER BY id ASC';
    $resCategory=$db->query($sql);

    *if ($resCategory->num_rows > 0) {*
        while($rowCategories = $resCategory->fetch_assoc()) {
            $category_tree_array[] = array("id" => $rowCategories['id'], "name" => $spacing . $rowCategories['name']);
            $category_tree_array = Self::categoryParentChildTree($rowCategories['id'], '    '.$spacing . '- ', $category_tree_array);
        }
    }

    return $category_tree_array;
}

请帮我这个函数输出这个错误

  

注意:未定义的属性:

中的PDOStatement :: $ mysqli_num_rows

1 个答案:

答案 0 :(得分:0)

出现通知,因为未创建对象。

用此代替行$resCategory=$db->query($sql);

if($resCategory = $db->query($sql)) {
    //continue with your code...
    if ($resCategory->num_rows > 0) {
    ...
}

else {
    // SQL Query didn't return anything
}