Exemple #1
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']);
     }
 }