Fatal error: Call to a member function fetch_array() on a non-object in

Fatal error: Call to a member function fetch_array() on a non-object in

找不到错误,有人可以帮我吗?

$sql_project_material = "SELECT * FROM project_material";
if($result_project_material = $connect->query($sql_project_material))
{
    $rows_project_material = $result_project_material->fetch_array();
    $total_project_material = $result_project_material->num_rows;
    $num_project_material = 0;
}

您的 $result_project_material 可能为空或您的查询失败。

尝试一步一步做,找出错误所在,调用前检查结果是否为空fetch_array()

$connect = new mysqli($dbhost, $dbuser, $dbpass, $dbname);

if ($connect->connect_errno) {
   printf("Connect failed: %s\n", $connect->connect_error());
   exit();
}

$result_project_material = $connect->query($sql_project_material);

if($total_project_material = $result_project_material->num_rows > 0) {
   while($result_array = $result_project_material->fetch_array()) {
       $rows_project_material[] = result_array;
   }
}else{
   $rows_project_material = array();
   echo "Empty Result";
}