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

业务场景:使用update语句去更新数据库字段。 原因:update接收值不正确。原来代码: $query = "UPDATE student SET date = now() WHERE id = $id";$result = $mysqli-query($query2) or die($mysqli-error); // 问题出现了在这句 $data = $result-fetch_assoc();  if ($data) {      $ary = arra

业务场景:使用update语句去更新数据库字段。

原因:update接收值不正确。原来代码:

$query = "UPDATE student SET date = now() WHERE id = $id";
$result = $mysqli->query($query2) or die($mysqli->error); // 问题出现了在这句  
$data = $result->fetch_assoc();

  if ($data) {
      $ary = array('data' => '', 'msg' => '更新成功', 'status' => '0');
  } else {
      $ary = array('data' => '', 'msg' => '更新失败', 'status' => '1');
  }
  exit(JSON($ary));
修改后的代码:
$query = "UPDATE student SET date = now() WHERE id = $id";
$result = $mysqli->query($query2); // 把or die($mysqli->error)删了
$data = $result->fetch_assoc();
  if ($data) {
      $ary = array('data' => '', 'msg' => '更新成功', 'status' => '0');
  } else {
      $ary = array('data' => '', 'msg' => '更新失败', 'status' => '1');
  }
  exit(JSON($ary));
问题就出在or die($mysqli->error)这里。

本文标题为:Fatal error: Call to a member function fetch_assoc() on a non-object in

基础教程推荐