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];
}