I have two PHP classes. One is for connecting to the database, building queries, executing them, and disconnecting from the database. The other class is for users: adding th
I'm debating whether I should connect to the database on the page globally and use that connection (passing the database object into the method of the user object), or whether I should connect and disconnect from the database from within the a user method itself.
Stop debating. Make the database class available to the functions that need it and handle the connection transparently, so that you have one connection per request. Doing multiple connects / disconnects is superfluous and only creates too much work that does not need to be done.
So actually you only need one connection variable (object). Make it available to the functions that need it (e.g. a database class that has it as a member) and you're fine. Whether or not you make that object globally available is your design decision.
Additionally take a look into a pattern called table data gateway and / or the active record pattern. Probably that's what you do with your user object, so you don't need to re-invent the wheel and you can take an existing library instead so you can better concentrate on the actual work that needs to be done in your application.