unidox Posted December 13, 2008 Share Posted December 13, 2008 I have a db class, it includes functions like connecting to the database, selecting the table, querying, inserting, ect. I was wondering how do I include that class in each of the classes I create like login classes and such. Link to comment https://forums.phpfreaks.com/topic/136787-db/ Share on other sites More sharing options...
xtopolis Posted December 13, 2008 Share Posted December 13, 2008 I don't think that you should "include" the db class so much as pass a db object to the login class to use.. If you are asking how to include the file on every page, you can write the __autoload($arg) function autoload (be sure to read the notes on making this a safe include/require) if you're asking about just USING the class in your other classes.. I usually create a $db object in the global scope, and pass it to my other class... i also use one instance. $db = MYSQL::getInstance('host','un','pw','database'); $auth = new Auth($db,$arg,$arg); Inside Auth I can use it such as: $sql = "SELECT username FROM myTable WHERE username='xtopolis'"; $result = $db->query($sql); Link to comment https://forums.phpfreaks.com/topic/136787-db/#findComment-714405 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.