you may have a static method in your database class that will return the instance itself.
$db = DB::getInstance();
In addition, you can implement a singleton pattern. You can read about it here.
PHP Templates
The main idea is that you save the database object in a static property, and then in getInstance check whether you set it to return or created a new one, the constructor must be closed so that the object cannot be created anywhere except getInstance .. this guarantees that there is always one instance of a DB object.
source share