fetchAll
returns a 2-dimensional array of all the results. To get just one row at a time, you should call $stmt->fetch()
, not $stmt->fetchAll()
.
while ($row = $stmt->fetch()) {
...
}
But since you're returning, you shouldn't use a loop at all. The return
statement will terminate the loop after the first iteration. Just use an if
statement.
if ($row = $stmt->fetch()) {
return $row['email'];
}
This whole code doesn't make much sense -- $newemail
is guaranteed to be the same as $email
, why are you returning it? It probably should be:
if ($stmt->fetch()) { // Email was found
return true;
} else {
return false;
}