如何解决这些错误警告:mysqli_query():, mysqli_num_rows()需要参数1,mysqli_fetch_assoc()需要参数1

时间:2016-07-10 11:46:16

标签: php mysqli

它显示如下错误:

Warning: mysqli_query(): Couldn't fetch mysqli in C:\xampp\htdocs\kidstore\admin\init\dataconfig.php on line 94

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in C:\xampp\htdocs\kidstore\admin\init\dataconfig.php on line 95

Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\kidstore\admin\add-category.php on line 142

这是我的代码:

// fetch all data from database for all category in display 
function select_categories($connectionStatus){
    $query = "SELECT * FROM `categories` WHERE parent = 0";
    $result = mysqli_query($connectionStatus, $query);
    if(mysqli_num_rows($result) > 0){
       mysqli_close($connectionStatus);
       return $result;
    }
    return false;

}

1 个答案:

答案 0 :(得分:0)

嗨问题出在这一行

 $result = mysqli_query($connectionStatus, $query);

添加mysqli_error()

   $result = mysqli_query($connectionStatus, $query) or die(mysqli_error($connectionStatus));

您的mysqli_connect()也在哪里。 您的query没有执行这就是您获得errors

的原因

如果一切正常,那么一旦在php中运行你的$query并检查它是否给出了结果。但在此之前请检查connection