Jump to content

Utilizing DB wrappers in other classes


valaris

Recommended Posts

Hi, right now im trying to write a small API that can hopefully grow over time.  Right now its functional with a class to handle all sql operations(queries and such), as well as having a few other classes for login.  My question, being fairly new to OOP in general, what is the best way to use this database class in my other classes?  Right now i am just creating a new instance of a db class and connecting/pumping queries out.  Is there a way i can use one connection for all classes?  I have about 6 classes right now to perform various unrelated tasks that all call a new database class each time they are run, is this the way i should be doing this?  Thanks again.

Link to comment
https://forums.phpfreaks.com/topic/111167-utilizing-db-wrappers-in-other-classes/
Share on other sites

Awesome.  Maybe I should move this to design with all my design questions ><.  Anyways i guess my next question involves implementation.  I've successfully made a database singleton class, and a user singleton class.  The main user class is responsible for mantaining the user object, of which other classes can derive from it (such as login).  How do i encorporate my database class into my login class?  Would the best way be to in the user class just make a class variable $db = mysql::getInstance(); ?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.