Trying to check if the user exists
$db = new PDO('sqlite:practice.sqlite');
$query = $db->prepare("SELECT EXISTS (SELECT 1 FROM users WHERE name = :name AND password = :password)");
$query->bindValue(':name', $_POST['name']);
$query->bindValue(':password', $password);
$result = $query->execute();
echo gettype($result);
echo $result;
Will always output a boolean with the value of 1. I have checked with wrong password, wrong username or both. Always the same. Is there something obvious I'm missing here?
edit: maybe its useful to note that I've also attempted this method
$db = new PDO('sqlite:practice.sqlite');
$query = $db->prepare("SELECT EXISTS (SELECT 1 FROM users WHERE name = ? AND password = ?)");
$query->execute([$_POST['name'], $password]);
$result = $query->fetch();
print_r($result);
which results in me getting
Array ( [EXISTS (SELECT 1 FROM users WHERE name = ? AND password = ?)] => 0 [0] => 0 )
every time whether the user exists or not. I have also tested this by adding an account with an unencrypted password. And then running the check with the raw $_POST['password'] value passed on. Which results in the same 0 in the $result array.
edit 2: after another suggestion I have tried out this answer, which yielded the same result where I get "doesn't exist" for freshly created users. This is the case with and without password encryption. The result of count($result) is always higher than 0.