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
Create a function that creates the connection on demand and provides access to the connection object:
function getDb() { static $db; if (!$db) $db = ...; return $db; }
Wrapped into class this approach is called Singleton
Singleton