Maybe this is an weary topic but I couldn't find discussions about this:
I have a small database abstraction layer that works fine. I create a new db object ($db = new CDatabase() for example) on a page, do some queries and print out the HTML.
How about when I'm using this class from another class. I have some classes that need to retrieve stuff from the DB, and multiple classes can be contributing to the output on one PHP page.
Should I instantiate the db object on the PHP page, making it global, then using the same global object on each class? This seems to violate something in the OO thinking.
Passing it as variables to each method seems tedious also.
On the other hand, if I create a new $db in every class (or method even), it seems to waste resources.
Any thoughts on this?
.samuli