So I've learnt a lot about PHP, and I started with the basics even if some of it is deprecated. Now I've got the knowledge down, I'm re-writing everything I've done to use PDO and class'. Now I've never used either but I'm slowly (slowly, slowly) understanding and getting my head around it. What I'd like to ask, is if I'm doing this right, if not where am I going wrong?
I basically have this function:
function user_exists($username) {
$username = sanitize($username);
$query = mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username'");
return (mysql_result($query, 0) == 1) ? true : false;
}
And I want to turn it into a class:
class user {
function exists($username) {
$username = $username;
$query = $db->query("SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username'");
$results = $query->fetchAll(PDO::FETCH_ASSOC);
}
}
Am I on the right track, should I be making the variables in that function (method) private to the "exists" method?
I plan to make a "users" class, with methods such as exists, banned, admin, ect. I think this is what I should be doing?
Thanks if anyone answers this.