I am pretty new to OOP and so this question is more to do with theory, than my actual code. I don't have access to my code at the moment but will add it soon.
I have a 'database' class which allows me to create new PDO connections and interact with various databases. I pass the database connection details when creating an object, and the __construct method builds the PDO connection with these values.
Then I have various methods for interacting with the database e.g prepare, execute etc
I created an object for each connection that I need, and this allows me to quickly query any of my databases by just calling the object and the method I want to use.
I am looking to create another class called 'users' which will allow me to interact with the users table. I would like methods to add, remove & modify user details. I was hoping to use an existing object to query the database within each of these methods. Rather than having to create a new object and pass it the connection details (So that I only have to update my connection details where the original object was created, rather than updating it in multiple places.
It seems that I cant do this because my 'database' object is outside of the scope of my 'users' class.
Can anyone advise me how I can make this object available within the 'users' class? More importantly is this the wrong approach and is there a better practice?