Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

I want to know if either email or username already exist on users table

hi guys, i want to know if users email or username already exist on my user table.' here is my code $checkfirst = Tblusers::findFirst(array("uname = '$uname'", "email = '$email'")); i think something wrong with my code.



17.4k
edited Jul '14
$checkfirst = Tblusers::findFirst(array(
    "uname = :uname: AND email = :email:",
    "bind" = array(
        "uname" => $uname,
        "email" => $email,
)));

or

$checkfirst = Tblusers::findFirst(array(
    "uname = ?1 AND email = ?2 ",
    "bind" = array(
        1 => $uname,
        2 => $email,
)));


17.4k
Accepted
answer

I have read on this forum that in case you only need to know if such user exists and you do not need to know values of its fields it is better to use count instead of findFirst.

$checkfirst = Tblusers::count(array(
    "uname = :uname: AND email = :email:",
    "bind" = array(
        "uname" => $uname,
        "email" => $email,
)));