I'm trying to find an alternate to my method of fetching all data in a function for a specific user where their session equals their username.
It was working fine until I moved hosting and now it throws errors. The following code is what I was using on my old hosting when it was working fine :
$username = 'Benza';
$query = "SELECT id, username, password, email, ip, lastonline, rank, register_time FROM users_ WHERE username = '$username'";
$result = $con->query($query);
return $result->fetch_all();
It says : Call to a member function fetch_all() on boolean
.
And when I try something like :
$username = 'Admin';
$query = "SELECT id, username, password, email, ip, lastonline, rank,
register_time FROM users_ WHERE username = '$username'";
$result = $con->query($query);
$data = mysqli_fetch_all($result,MYSQLI_ASSOC);
return $data;
I get Warning: mysqli_fetch_all() expects parameter 1 to be mysqli_result, boolean given Warning: Invalid argument supplied for foreach()
I'm calling my foreach functions as shown below (because the above code is in a function in the same class) :
$users = $this->grabUserInfos($con);
foreach ($users as $user) {
$username = $user[1];
$email = $user[3];
}
The problem seems to be that the part where the query is executed does not work anymore:
$result = $con->query($query);
The fact that you have an boolean in $result means that something went wrong with the query function. Because of that the fetch_all and the mysqli_fetch_all() function can not work correctly.
You should take a look at that part and find out why the query fails.