Beispiel #1
0
 protected function getOptions()
 {
     // Initialize variables.
     // This gets the connectors available in the platform and supported by the server.
     $available = MDatabase::getConnectors();
     $supported = $this->element['supported'];
     if (!empty($supported)) {
         $supported = explode(',', $supported);
         foreach ($supported as $support) {
             if (in_array($support, $available)) {
                 $options[$support] = ucfirst($support);
             }
         }
     } else {
         foreach ($available as $support) {
             $options[$support] = 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[''] = MText::_('MNONE');
     }
     return $options;
 }
Beispiel #2
0
 protected function connect()
 {
     // Build the configuration object to use for MDatabase.
     $options = array('driver' => $this->driver, 'host' => $this->host, 'user' => $this->user, 'password' => $this->password, 'database' => $this->database, 'prefix' => $this->prefix);
     try {
         $db = MDatabase::getInstance($options);
         if ($db instanceof Exception) {
             throw new LogException('Database Error: ' . (string) $db);
         }
         if ($db->getErrorNum() > 0) {
             throw new LogException(MText::sprintf('MLIB_UTIL_ERROR_CONNECT_DATABASE', $db->getErrorNum(), $db->getErrorMsg()));
         }
         // Assign the database connector to the class.
         $this->dbo = $db;
     } catch (RuntimeException $e) {
         throw new LogException($e->getMessage());
     }
 }
Beispiel #3
0
 protected 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;
     // Make sure the MySQL extension for PHP is installed and enabled.
     if (!function_exists('mysql_connect')) {
         if (MError::$legacy) {
             $this->errorNum = 1;
             $this->errorMsg = MText::_('MLIB_DATABASE_ERROR_ADAPTER_MYSQL');
             return;
         } else {
             throw new MDatabaseException(MText::_('MLIB_DATABASE_ERROR_ADAPTER_MYSQL'));
         }
     }
     // Attempt to connect to the server.
     if (!($this->connection = @mysql_connect($options['host'], $options['user'], $options['password'], true))) {
         // Legacy error handling switch based on the MError::$legacy switch.
         // @deprecated  12.1
         if (MError::$legacy) {
             $this->errorNum = 2;
             $this->errorMsg = MText::_('MLIB_DATABASE_ERROR_CONNECT_MYSQL');
             return;
         } else {
             throw new MDatabaseException(MText::_('MLIB_DATABASE_ERROR_CONNECT_MYSQL'));
         }
     }
     // Finalize initialisation
     parent::__construct($options);
     // Set sql_mode to non_strict mode
     mysql_query("SET @@SESSION.sql_mode = '';", $this->connection);
     // If auto-select is enabled select the given database.
     if ($options['select'] && !empty($options['database'])) {
         $this->select($options['database']);
     }
 }
Beispiel #4
0
 protected static function createDbo()
 {
     mimport('framework.database.table');
     $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);
     $db = MDatabase::getInstance($options);
     if ($db instanceof Exception) {
         if (!headers_sent()) {
             header('HTTP/1.1 500 Internal Server Error');
         }
         mexit('Database Error: ' . (string) $db);
     }
     if ($db->getErrorNum() > 0) {
         die(sprintf('Database connection error (%d): %s', $db->getErrorNum(), $db->getErrorMsg()));
     }
     $db->setDebug($debug);
     return $db;
 }
Beispiel #5
0
 public function setDb(MDatabase $db)
 {
     $this->db = $db;
     $this->platform = $db->getPlatForm();
 }