Is it possible and advisable to move the creation of a MySQL database object from the index.php (FrontController) to a Bootstrap class in PHP frameworks like Zend?

Moving the creation of a MySQL database object from the index.php (FrontController) to a Bootstrap class in PHP frameworks like Zend is both possible and advisable. By doing so, you can centralize the database connection logic and make it easier to manage and reuse throughout your application. This approach follows the principle of separation of concerns and helps in keeping your codebase clean and organized.

// Bootstrap class in Zend Framework
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
    protected function _initDb()
    {
        $config = $this->getOption('db');
        $db = Zend_Db::factory($config['adapter'], $config['params']);
        Zend_Db_Table_Abstract::setDefaultAdapter($db);
        Zend_Registry::set('db', $db);
        return $db;
    }
}

// index.php
$application = new Zend_Application(
    APPLICATION_ENV,
    APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap()
            ->run();