Back to Factory class

Method createDbo

protected static \Joomla\Database\DatabaseDriver
createDbo
()
Create a database object
Returns
  • \Joomla\Database\DatabaseDriver
Since
  • 1.7.0
Deprecated
  • 5.0
-
  • \Joomla\Database\DatabaseDriver
Class: Factory
Project: Joomla

Method createDbo - Source code

/**
 * Create a database object
 *
 * @return  DatabaseDriver
 *
 * @see         DatabaseDriver
 * @since       1.7.0
 * @deprecated  5.0  Use the database service in the DI container
 */
protected static function createDbo()
{
    @trigger_error(sprintf('%1$s() is deprecated, register a service provider to create a %2$s instance instead.', __METHOD__, DatabaseInterface::class), E_USER_DEPRECATED);
    $conf = self::getConfig();
    $host = $conf->get('host');
    $user = $conf->get('user');
    $password = $conf->get('password');
    $database = $conf->get('db');
    $prefix = $conf->get('dbprefix');
    $driver = $conf->get('dbtype');
    $options = array('driver' => $driver, 'host' => $host, 'user' => $user, 'password' => $password, 'database' => $database, 'prefix' => $prefix);
    if ((int) $conf->get('dbencryption') !== 0) {
        $options['ssl'] = ['enable' => true, 'verify_server_cert' => (bool) $conf->get('dbsslverifyservercert')];
        foreach (['cipher', 'ca', 'key', 'cert'] as $value) {
            $confVal = trim($conf->get('dbssl' . $value, ''));
            if ($confVal !== '') {
                $options['ssl'][$value] = $confVal;
            }
        }
    }
    try {
        $db = DatabaseDriver::getInstance($options);
    } catch (\RuntimeException $e) {
        if (!headers_sent()) {
            header('HTTP/1.1 500 Internal Server Error');
        }
        jexit('Database Error: ' . $e->getMessage());
    }
    return $db;
}