I built myself a MySQL class which I use in all my projects. I'm about to start a project that is heavily based on user accounts and I plan on building my own class for this aswell. The thing is, a lot of the methods in the user class will be MySQL queries and methods from the MySQL class.
For example, I have a method in my user class to update someone's password:
class user() {
function updatePassword($usrName, $newPass)
{
$con = mysql_connect('db_host', 'db_user', 'db_pass');
$sql = "UPDATE users SET password = '$newPass' WHERE username = '$userName'";
$res = mysql_query($sql, $con);
if($res) return true;
mysql_close($con);
}
}
(I kind of rushed this so excuse any syntax errors :) )
As you can see that would use MySQL to update a users password, but without using my MySQL class, is this correct? I see no way in which I can use my MySQL class within my users class without it seeming dirty. Do I just use it the normal way like $DB = new DB();
? That would mean including my mysql.class.php
somewhere too...
I'm quite confused about this, so any help would be appreciated, thanks.