/**
  * Method to get the list of database options.
  *
  * This method produces a drop down list of available databases supported
  * by JDatabaseDriver classes that are also supported by the application.
  *
  * @return  array    The field option objects.
  *
  * @since   11.3
  * @see		JDatabaseDriver
  */
 protected function getOptions()
 {
     // This gets the connectors available in the platform and supported by the server.
     $available = Driver::getConnectors();
     /**
      * This gets the list of database types supported by the application.
      * This should be entered in the form definition as a comma separated list.
      * If no supported databases are listed, it is assumed all available databases
      * are supported.
      */
     $supported = $this->element['supported'];
     if (!empty($supported)) {
         $supported = explode(',', $supported);
         foreach ($supported as $support) {
             if (in_array($support, $available)) {
                 $options[$support] = Text::_(ucfirst($support));
             }
         }
     } else {
         foreach ($available as $support) {
             $options[$support] = Text::_(ucfirst($support));
         }
     }
     // This will come into play if an application is installed that requires
     // a database that is not available on the server.
     if (empty($options)) {
         $options[''] = Text::_('JNONE');
     }
     return $options;
 }
 /**
  * Database object constructor
  *
  * @param   array  $options  List of options used to configure the connection
  *
  * @since	12.1
  */
 public function __construct($options)
 {
     $options['host'] = isset($options['host']) ? $options['host'] : 'localhost';
     $options['user'] = isset($options['user']) ? $options['user'] : '';
     $options['password'] = isset($options['password']) ? $options['password'] : '';
     $options['database'] = isset($options['database']) ? $options['database'] : '';
     // Finalize initialization
     parent::__construct($options);
 }
 /**
  * Constructor.
  *
  * @param   array  $options  List of options used to configure the connection
  *
  * @since   12.1
  */
 public function __construct($options)
 {
     // Get some basic values from the options.
     $options['host'] = isset($options['host']) ? $options['host'] : 'localhost';
     $options['user'] = isset($options['user']) ? $options['user'] : '';
     $options['password'] = isset($options['password']) ? $options['password'] : '';
     $options['database'] = isset($options['database']) ? $options['database'] : '';
     $options['select'] = isset($options['select']) ? (bool) $options['select'] : true;
     // Finalize initialisation
     parent::__construct($options);
 }
 /**
  * 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;
 }
 /**
  * Sets the SQL statement string for later execution.
  *
  * @param   mixed    $query          The SQL statement to set either as a JDatabaseQuery object or a string.
  * @param   integer  $offset         The affected row offset to set.
  * @param   integer  $limit          The maximum affected rows to set.
  * @param   array    $driverOptions  The optional PDO driver options
  *
  * @return  JDatabaseDriver  This object to support method chaining.
  *
  * @since   12.1
  */
 public function setQuery($query, $offset = null, $limit = null, $driverOptions = array())
 {
     $this->connect();
     $this->freeResult();
     if (is_string($query)) {
         // Allows taking advantage of bound variables in a direct query:
         $query = $this->getQuery(true)->setQuery($query);
     }
     if ($query instanceof Limitable && !is_null($offset) && !is_null($limit)) {
         $query->setLimit($limit, $offset);
     }
     $sql = $this->replacePrefix((string) $query);
     $this->prepared = $this->connection->prepare($sql, $driverOptions);
     // Store reference to the JDatabaseQuery instance:
     parent::setQuery($query, $offset, $limit);
     return $this;
 }
 /**
  * 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;
 }
 /**
  * Method to unlock the database table for writing.
  *
  * @return  boolean  True on success.
  *
  * @since   11.1
  */
 protected function _unlock()
 {
     $this->_db->unlockTables();
     $this->_locked = false;
     return true;
 }