Last active
September 5, 2015 22:43
-
-
Save HotelCalifornia/6d0845f9236cdac1d07f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# instead of testing for the user existing, test if the user doesn't exist | |
function user_not_exists($username) | |
{ | |
$connection = $this->get_connection(); | |
$stmt = $connection->prepare("SELECT `username` FROM users WHERE username = ?;"); | |
$stmt->bindValue(1, $username, PDO::PARAM_STR); | |
$stmt->execute(); | |
return empty($stmt->fetchAll(PDO::FETCH_ASSOC)); | |
# PDOStatement::fetchAll returns an array, so it's easiest to test if the array is empty (no results found) | |
# if you want to keep the function as user_exists(...), try returning $stmt->fetchAll(PDO::FETCH_ASSOC)[0] | |
# so that you get the actual result, and not just the array | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment