Request:
select * from (select count(`id`) from `users` where `login` = :l) as one, (select count(`id`) from `users` where `email` = :e) as two Must return the number of matches. But for some reason this does not happen.
@rnddev , if you need to check the presence of the user, then you need to use constructions like
SELECT 1 FROM `users` WHERE `login` = :login OR `email` = :email As for the above query, so one and two there are aliases not of the fields, but of the tables, because the selects are listed in FROM , and the values are returned in COUNT(`id`) and elements with a numeric index (unless PDO::FETCH_* ). In order for one and two to become column aliases, you need this query:
select * from (select count(`id`) AS one from `users` where `login` = :l) as login_matches, (select count(`id`) AS two from `users` where `email` = :e) as email_matches OR I can not use, because I need to show what is busy, login or email. - Bastianeusers WHERE EXISTS (SELECT 1 FROM users WHERE login =: subject) UNION SELECT 'email' FROM users WHERE EXISTS (SELECT 1 FROM users WHERE email =: subject) UNION SELECT 'nothing' LIMIT 1 - etkiSource: https://ru.stackoverflow.com/questions/368633/
All Articles
$check['one']is called later in the code, while the desired array is obtained as follows: $ data = $ check-> fetch (); - etkicount(id), otherwise mysql will glue them into one field and how horrible it is. - Yura Ivanov