Welcome Guest, Not a member yet? Register   Sign In
Easy way to check existence of a user in DB ? ( Newbie )
#5

[eluser]tekhneek[/eluser]
I could be wrong, but wouldn't this achieve the same thing with less code?
Code:
$query = $this->db->get_where('users', array('username' => $username, 'password' => $password));
if ($query->num_rows() === 1) {
   return $query;
} else {
   return false;
}
I've also noticed that using $this->db->where() is very handy in general, but obviously in situations where conditions are needed say for specific preset rows from a database like:
Code:
function get_categories($featured = false) {
    if ($featured !== false) {
        $this->db->where('featured', true);
    }

    $query = $this->db->get('categories');

    if ($query->num_rows() > 0) {
        return $query;
    }

    return false;
}
etc.


Messages In This Thread
Easy way to check existence of a user in DB ? ( Newbie ) - by El Forum - 05-11-2009, 02:08 AM



Theme © iAndrew 2016 - Forum software by © MyBB