I am new to using classes in PHP, I just realized, in most of my class methods, I need to do some mysql queries. I have another class that handles my connection and queries but how should I go about calling that class from other classes? Doesn’t this kind of defeat the purpose of using classes if all my classes rely on my DB class?
Share
this is usually solved with the Singleton or Factory pattern…
when you need to use the db, you snatch the app’s db object:
getDb returns a static instance.
or:
returns a static instance if it exists, or creates a new db handle for that dsn…