/** * Method to connect to the database server based on object properties. * * @return void * * @since 11.1 * @throws \RuntimeException */ protected function connect() { // Build the configuration object to use for JDatabaseDriver. $options = array('driver' => $this->driver, 'host' => $this->host, 'user' => $this->user, 'password' => $this->password, 'database' => $this->database, 'prefix' => $this->prefix); $db = Driver::getInstance($options); // Assign the database connector to the class. $this->dbo = $db; }
/** * Create an database object * * @return Driver * * @see Driver * @since 11.1 */ protected static function createDbo() { $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'); $debug = $conf->get('debug'); $options = array('driver' => $driver, 'host' => $host, 'user' => $user, 'password' => $password, 'database' => $database, 'prefix' => $prefix); try { $db = Driver::getInstance($options); } catch (RuntimeException $e) { if (!headers_sent()) { header('HTTP/1.1 500 Internal Server Error'); } jexit('Database Error: ' . $e->getMessage()); } $db->setDebug($debug); return $db; }