I'm running PHP 7.0 and connected to a mysql db with a record matching the query in the below:
$query = mysqli_query($conn, "SELECT COUNT(`user_id`) FROM `users` WHERE `username` = 'baz'");
$row = mysqli_fetch_row($query);
print_r($row[0]);
Print outputs 1, as expected as there is only one record matching that username.
However, the following function returns false
function user_exists(){
$exists_query = mysqli_query($conn, "SELECT COUNT(`user_id`) FROM `users` WHERE `username` = 'baz'");
$row = mysqli_fetch_row($exists_query);
return ($row[0] == 1) ? True : False;
}
But I would expect it to be true. Am I misusing the fetch function?