OOP CMS object design for accessing the database
I'm trying to make a small cms in php and mysql, and want it to be o开发者_C百科bject-oriented
I have a class DbConnector that handles all sql queries. Then I have some other classes that needs to alter the database through the DbConnector.
As I see i I have to either send the DbConnector instance as a parameter in every class initialization, or I can make a new DbConnector instance for each class, which to me seems pretty unnecessary.
What is the preferred way to do this or is it all wrong?
The preferred way of doing this would be Dependency Injection, the lazy / easy / OK for small scale way could be a Singleton database object.
精彩评论