Check out my PHP class (24th Mar 08 at 1:15am UTC) See if I can improve my PHP class
Ok so i've been reading about classes and I made my first class. I don't want to form bad habbits so I want you guys to tell me if I'm doing it right or if theres a better way to do something that I"m doing?
$query =$db->do_query("SELECT * FROM support_users WHERE username='admin'");
$row =$db->get_assoc($query);
echo $row['username'];
?>
Also I'm going to create a new file for each class and it's subclasses so like all classes relating to users will be in the users.php file which is in the framework folder. Do you guys do something similar?
Re: Check out my PHP class (24th Mar 08 at 2:32am UTC)
Yes I do. ^_^
Basically, it'd be like creating a method of the database class called query that would just call mysql_query. It performs an already-existing function with little to no modification. The benefit is, all your calls are to this class' method, so you can update how you query things easily, and if you want to, you can easily fill in required but static fields (e.g., the host, username, password, etc.) in the method, meaning you don't have to type them hundreds of times, and get screwed when one changes.