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
Call to a member function fetch_assoc() on boolean
but I don't see how this is the case.
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)
}
and
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
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()) {}
EDIT: 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()) {}
The output is:
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
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!