PHP数据库使用总结

1、使用php 查询数据库中的数据时,出现了:

报错提示:
Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, bool given in D:\site\public\class\db.class.php on line 77

只需要加入简单一行代码就可以找出问题所在:

处理方法是,在$res = mysqli_query($conn, $query);后加上这样一段代码: 

if (!$res) {
    printf("Error: %s\n", mysqli_error($conn));
    exit();
}

 
这样就可以输出是什么错误。
发现原来是查询语句发生错误,而不是mysqli_fetch_assoc的参数问题
  

猜你喜欢

转载自blog.csdn.net/qq_31432773/article/details/118381760