I'm having a problem with this code:
$loginrequest = $mysqli->prepare(
"SELECT name, password, salt FROM users WHERE name = ? OR email = ?");
$loginrequest->bind_param("ss", $login, $login);
$loginrequest->execute();
$loginrequest->bind_result($name, $encrypted_password, $salt);
while ($loginrequest->fetch()) {
$hash = $this->checkhashSSHA($salt, $password);
if ($encrypted_password == $hash) {
return $name;
}
else {
return false;
}
}
As you can see I want to check a user login, and if the password is correct I want to return the username, otherwise false.
But don't I have to close the $mysqli
query doing this?
$loginrequest->close();
$mysqli->close();
Because the value $name
is only available in the while loop (if I understood this correctly). I mean I could declare a string before and change it to the $name
value, but is it necessary to close her?
By the way I can't use store_result
since the PHP Version is too old.