Logout and db query method