警告:mysqli_fetch_assoc()期望参数1为mysqli_result,给定布尔值 [英] Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given

查看:272
本文介绍了警告:mysqli_fetch_assoc()期望参数1为mysqli_result,给定布尔值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经查看了与该警告"相关的所有其他问题,但没有一个与我的问题相同.我的问题似乎很简单,尽管我似乎无法弄清楚.我已经尝试过我在google和此处看到的所有解决方案,但是我对php/mysqli不够熟悉,无法解决它.预先感谢!

I've looked over all the other questions pertaining to this 'warning' but none are the same as my issue. My issue seems to be quit simple though i just can't seem to figure it out. I've tried every solution i've seen on google and here but i'm not familiar enough with php/mysqli to resolve it. Thanks in advance!

<?php
$db = new mysqli('localhost', 'root', '', 'game');

if($db->connect_errno > 0){
    die('Unable to connect [' . $db->connect_errno . ']');
}

$query = mysqli_query($db, "SELECT * FROM `characters`");

$query_result = array();

while ($row = mysqli_fetch_assoc($query)) {
    $query_result[$row['id']] = array(

        'name' => $row['name'],
        'name' => $row['race'],
        'name' => $row['level']
    );
}

?>

推荐答案

通常在mysqli_query无法正常运行时会发生这种情况.检查$ query是否正确执行或是否包含任何内容.问题可能与连接有关,也可能与查询有关,或者与表有关.确保$ query包含结果.

This happens usually when the mysqli_query hasnt run properly. Check whether $query is executed properly or does it contains anything or not. The problem may be with the connection or it may be with the query or it may be with the tables. Be sure $query contains the results.

尝试一下

if (!$query) {
        echo 'MySQL Error: ' . mysqli_error();
        exit;
    }

让我们知道什么是mysql错误

Let us know what is the mysql error

这篇关于警告:mysqli_fetch_assoc()期望参数1为mysqli_result,给定布尔值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆