On Mon, 12 Jan 2004, rogue wrote: > i am working out the finishing touches on a authentication class that > uses mysql to store the time of last access and some other goodies. > > my question is, when developing a class that uses a database, what is > the best way to handle the database bit? for now i just set the > connection in an .inc file and include that in the class, but there has > got to be a better way - especially for portability sake.
As previously suggested by another poster, check out PEAR's DB class. I wrote my own database class and used it in almost everything I wrote for a long time, but eventually for "portability" sake, I moved to PEAR::DB. Just instantiate the database connection object and attach a reference to your authentication object. Then access the database object's methods as you normally would from the object reference attached to your auth object. Structure things right and it's very easy to do. It avoids the pitfalls of some of the other approaches, like accessing some sort of global. The DB class also allows you some manner of database abstraction for a modicum of portability if you should need it (it's the SQL queries themselves that are not always portable, so you have to solve that). If you've never looked at PEAR, the DB class is a good start. Also, despite all it's features, it's quite fast! -- Kelly Hallman // Ultrafancy -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php