php向数据库插入数据 warning mysqli_fetch_array 出错
<?php
$conn=mysqli_connect('localhost','root','');
mysqli_query($conn,'use newcms');
mysqli_set_charset($conn,'utf8');
$sql='select * from news';
$result=mysqli_query($conn,$sql);
echo "<table border='1'>";
echo "<tr><th>序号</th>";
echo "<th>新闻标题</th>";
echo "<th>新闻类别</th>";
echo "<th>发布时间</th>";
echo "<th>发布人</th>";
echo "<th>序号</th>";
echo "<th>点击次数</th>";
echo "<th>新闻内容</th></tr>";
while($row=mysqli_fetch_array($result)){//这句报错
?>
通过错误提示知道mysqli_query执行sql语句失败了,执行sql语句失败会返回false,所以mysqli_fetch_array报那个错误需要mysqli_result,而不是布尔值
检查数据库表名称是否为news,并且大小写是一致的,有些mysql数据库版本是大小写敏感的,修改mysql的配置my.ini,将lower_case_table_names配置为
lower_case_table_names=0
如果没有在在[mysqld]节点下添加lower_case_table_names=0
加这个参数试试,加上这个还报错的话,那就是$result=mysqli_query($conn,$sql); 这句的结果问题了
while($row=mysqli_fetch_array($result,MYSQLI_ASSOC)){
您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!