“在布尔值上调用成员函数 fetch_assoc()" [英] "Call to a member function fetch_assoc() on boolean"

查看:44
本文介绍了“在布尔值上调用成员函数 fetch_assoc()"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看过很多关于这个错误的问题,但似乎没有一个能解决我的问题......抱歉,如果我错过了一个.

I've seen a bunch of questions about this error, but none of them seemed to have an answer that solved my problem... Sorry if I missed one.

我的脚本一直给我一个错误提示

My script keeps giving me an error saying

在 boolean 上调用成员函数 fetch_assoc()

Call to a member function fetch_assoc() on boolean

但我不明白这是怎么回事.

but I don't see how this is the case.

$mysqli_query$mysqli_query->fetch_assoc() 都是对象.那些分别是:

Both $mysqli_query and $mysqli_query->fetch_assoc() are objects. Those respectively being:

object(mysqli_result)#4 (5) {
["current_field"]=>
  int(0)
["field_count"]=>
  int(2)
["lengths"]=>
  NULL
["num_rows"]=>
  int(1)
["type"]=>
  int(0)
}

array(2) {
["date"]=>
  string(10) "2016-11-19"
["roles"]=>
  string(241) "{"eu":{"host":{"max":2,"0":"U0SEMUG8L"},"chat":{"max":1,"0":"U0SEMUG8L"},"bg":{"max":2,"0":"U0SEMUG8L"}},"us":{"host":{"max":2,"0":"U0SEMUG8L","1":"U0SEMUG8L","2":"U0SEMUG8L"},"chat":{"max":1,"0":"U0SEMUG8L","1":"U0SEMUG8L"},"bg":{"max":2}}}"
}

这些也会产生同样的错误:

These also produce the same error:

SELECT * FROM `hosting_signups`
SELECT * FROM `hosting_signups` WHERE 1

在 PhpMyAdmin 中运行以下内容时,它工作正常:

When the following is run in PhpMyAdmin, it works fine:

SELECT * FROM `hosting_signups` WHERE `date`='2016-11-19'

有谁知道我做错了什么?相关代码如下:

Does anyone know what I'm doing wrong? Here is the relevant code:

$mysqli_cmd = "SELECT * FROM `hosting_signups` WHERE `date`='" . $next_karaoke->format("Y-m-d") . "'";
$mysqli_query = $mysqli->query($mysqli_cmd);
//var_dump($mysqli_query->fetch_assoc()); // Oddly, when uncommented this terminates the 
                                          // whole while loop below, and the error is not 
                                          // produced but my code inside does not run. I'm 
                                          // not sure if this is at all related to my problem.

while($row = $mysqli_query->fetch_assoc()) {}

我稍微修改了我的代码,并进行了更多调试,如下:

I've modified my code a bit, with some more debugging, to be:

$mysqli_cmd = "SELECT * FROM `hosting_signups` WHERE `date`='" . $next_karaoke->format("Y-m-d") . "'";
$mysqli_query = $mysqli->query($mysqli_cmd);

var_dump($mysqli_cmd);
var_dump($mysqli->error);

while($row = $mysqli_query->fetch_assoc()) {}

输出为:

string(57) "SELECT * FROM `hosting_signups` WHERE `date`='2016-11-19'"
string(0) ""
Fatal error:  Call to a member function fetch_assoc() on boolean in 
/home2/bugfroggy/public_html/hosting_signup.php on line 63

编辑 2:这是一个愚蠢的错误.我不小心更改了 while 循环中 $mysqli_query 的值,而不是 another 的查询变量我在循环内部做的查询.问题解决了!

EDIT 2: Was a stupid mistake on my end.. I was accidentally changing the value of $mysqli_query in the while loop instead of the query variable for another query I was doing inside of the loop. Problem solved!

推荐答案

这是我的一个愚蠢的错误.. 我不小心更改了 while$mysqli_query 的值code> 循环而不是我在循环内执行的另一个查询的查询变量.

Was a stupid mistake on my end.. I was accidentally changing the value of $mysqli_query in the while loop instead of the query variable for another query I was doing inside of the loop.

这篇关于“在布尔值上调用成员函数 fetch_assoc()"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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