Hi folks,
I have a little problem. I have written a database class so I can connect to my database and perform various operations through a few simple to use functions. It also logs my queries and displays them at the bottom of the page when being viewed in my dev environment.
The trouble is when other objects need access to the DB the only way I can see that they can get access to that DB object is for me to pass it as a variable to their constructors. This seems a little inelegant to me. I don't want to create a new object inside each class because 1) I want to restrict the DB login info to one place (can't put it inside the DB class because I want it to be portable) and 2) I don't want multiple copies of the DB object as my query log will be fragmented across all the different classes.
Making the variable the object is assigned to global does not give different classes access to it, and so apart from passing the class to every object that needs it I can't see a way of getting access... which also means I have to have an instance of every class if I want to use the database - no static functions unless I pass the DB object to each of them too!!
Does anyone have any suggestions or know of a solution?
Many thanks!