/**
  * Database object constructor
  * @param	array	List of options used to configure the connection
  */
 public function __construct($options)
 {
     $this->driverType = 'mysql';
     // Init
     $this->nameQuote = '`';
     $host = array_key_exists('host', $options) ? $options['host'] : 'localhost';
     $port = array_key_exists('port', $options) ? $options['port'] : '';
     $user = array_key_exists('user', $options) ? $options['user'] : '';
     $password = array_key_exists('password', $options) ? $options['password'] : '';
     $database = array_key_exists('database', $options) ? $options['database'] : '';
     $prefix = array_key_exists('prefix', $options) ? $options['prefix'] : '';
     $select = array_key_exists('select', $options) ? $options['select'] : true;
     if (!empty($port)) {
         $host .= ':' . $port;
     }
     // finalize initialization
     parent::__construct($options);
     // Open the connection
     $this->host = $host;
     $this->user = $user;
     $this->password = $password;
     $this->_database = $database;
     $this->selectDatabase = $select;
     if (!is_resource($this->connection) || is_null($this->connection)) {
         $this->open();
     }
 }
 /**
  * Database object constructor
  * @param	array	List of options used to configure the connection
  */
 public function __construct($options)
 {
     // Get best matching Akeeba Backup driver instance
     if (class_exists('JFactory')) {
         $this->dbo = JFactory::getDBO();
     } else {
         $driver = AEPlatform::getInstance()->get_default_database_driver(false);
         $this->dbo = new $driver($options);
     }
     // Propagate errors
     $this->propagateFromObject($this->dbo);
     $this->nameQuote = '`';
     parent::__construct($options);
     $this->database = $options['database'];
 }
 public function open()
 {
     // perform a number of fatality checks, then return gracefully
     if (!function_exists('mysql_connect')) {
         $this->errorNum = 1;
         $this->errorMsg = 'The MySQL adapter "mysql" is not available.';
         return;
     }
     if (!($this->resource = @mysql_connect($this->host, $this->user, $this->password, true))) {
         $this->errorNum = 2;
         $this->errorMsg = 'Could not connect to MySQL';
         return;
     }
     parent::open();
     $this->select($this->database);
 }
 /**
  * Constructor.
  *
  * @param   array  $options  List of options used to configure the connection
  *
  * @since   11.1
  */
 public function __construct($options)
 {
     $this->driverType = 'mssql';
     // Get some basic values from the options.
     $host = array_key_exists('host', $options) ? $options['host'] : 'localhost';
     $port = array_key_exists('port', $options) ? $options['port'] : '';
     $user = array_key_exists('user', $options) ? $options['user'] : '';
     $password = array_key_exists('password', $options) ? $options['password'] : '';
     $database = array_key_exists('database', $options) ? $options['database'] : '';
     $prefix = array_key_exists('prefix', $options) ? $options['prefix'] : '';
     $select = array_key_exists('select', $options) ? $options['select'] : true;
     // Build the connection configuration array.
     $this->connectionConfig = array('Database' => $database, 'uid' => $user, 'pwd' => $password, 'CharacterSet' => 'UTF-8', 'ReturnDatesAsStrings' => true);
     parent::__construct($options);
     $this->host = $host;
     $this->user = $user;
     $this->password = $password;
     $this->_database = $database;
     $this->selectDatabase = $select;
     if (!is_resource($this->connection)) {
         $this->open();
     }
 }
 /**
  * Reverse engineers the View definitions of this database
  *
  * @param   AEAbstractDriver  $dbi  Database connection to INFORMATION_SCHEMA
  */
 protected function reverse_engineer_views(&$dbi)
 {
     // @TODO - THIS IS NOT PORTED TO SQL SERVER YET!
     $schema_name = $this->database;
     $sql = 'SELECT * FROM `views` WHERE `table_schema` = ' . $dbi->quote($schema_name);
     $dbi->setQuery($sql);
     $all_views = $dbi->loadObjectList();
     $registry = AEFactory::getConfiguration();
     $root = $registry->get('volatile.database.root', '[SITEDB]');
     // If we have filters, make sure the tables pass the filtering
     $filters = AEFactory::getFilters();
     // First pass: populate the table_name_map
     if (!empty($all_views)) {
         foreach ($all_views as $table_object) {
             // Extract the table name
             $table_name = $table_object->TABLE_NAME;
             // Filter and convert
             if (substr($table_name, 0, 3) == '#__') {
                 AEUtilLogger::WriteLog(_AE_LOG_WARNING, __CLASS__ . " :: Table {$table_name} has a prefix of #__. This would cause restoration errors; table skipped.");
                 continue;
             }
             $table_abstract = $this->getAbstract($table_name);
             if (substr($table_abstract, 0, 4) != 'bak_') {
                 // Apply exclusion filters
                 if (!$filters->isFiltered($table_abstract, $root, 'dbobject', 'all')) {
                     AEUtilLogger::WriteLog(_AE_LOG_INFO, __CLASS__ . " :: Adding {$table_name} (internal name {$table_abstract})");
                     $this->table_name_map[$table_name] = $table_abstract;
                 } else {
                     AEUtilLogger::WriteLog(_AE_LOG_INFO, __CLASS__ . " :: Skipping {$table_name} (internal name {$table_abstract})");
                     continue;
                 }
             } else {
                 AEUtilLogger::WriteLog(_AE_LOG_INFO, __CLASS__ . " :: Backup table {$table_name} automatically skipped.");
                 continue;
             }
         }
     }
     // Second pass: get the create commands
     if (!empty($all_views)) {
         foreach ($all_views as $table_object) {
             // Extract the table name
             $table_name = $table_object->TABLE_NAME;
             if (!in_array($table_name, $this->table_name_map)) {
                 // Skip any views which have been filtered out
                 continue;
             }
             $table_abstract = $this->getAbstract($table_name);
             // Still here? The view is added. We now have to store its
             // create command, dependency info and so on
             $new_entry = array('type' => 'view', 'dump_records' => false);
             $dependencies = array();
             $table_sql = 'CREATE OR REPLACE VIEW `' . $table_name . '` AS ' . $table_object->VIEW_DEFINITION;
             $old_table_sql = $table_sql;
             foreach ($this->table_name_map as $ref_normal => $ref_abstract) {
                 if ($pos = strpos($table_sql, "`{$ref_normal}`")) {
                     // Add a reference hit
                     $this->dependencies[$ref_normal][] = $table_name;
                     // Add the dependency to this table's metadata
                     $dependencies[] = $ref_normal;
                     // Do the replacement
                     $table_sql = str_replace("`{$ref_normal}`", "`{$ref_abstract}`", $table_sql);
                 }
             }
             // On DB only backup we don't want any replacing to take place, do we?
             if (!AEUtilScripting::getScriptingParameter('db.abstractnames', 1)) {
                 $table_sql = $old_table_sql;
             }
             // Replace newlines with spaces
             $table_sql = str_replace("\n", " ", $table_sql) . ";\n";
             $table_sql = str_replace("\r", " ", $table_sql);
             $table_sql = str_replace("\t", " ", $table_sql);
             $new_entry['create'] = $table_sql;
             $new_entry['dependencies'] = $dependencies;
             $this->tables_data[$table_name] = $new_entry;
         }
     }
 }
Example #6
0
 /**
  * Database object constructor
  *
  * @param   array $options List of options used to configure the connection
  *
  */
 public function __construct($options)
 {
     $this->driverType = 'postgresql';
     $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'] : '';
     $host = array_key_exists('host', $options) ? $options['host'] : 'localhost';
     $port = array_key_exists('port', $options) ? $options['port'] : '';
     $user = array_key_exists('user', $options) ? $options['user'] : '';
     $password = array_key_exists('password', $options) ? $options['password'] : '';
     $database = array_key_exists('database', $options) ? $options['database'] : '';
     $prefix = array_key_exists('prefix', $options) ? $options['prefix'] : '';
     $select = array_key_exists('select', $options) ? $options['select'] : true;
     // Finalize initialization
     parent::__construct($options);
     if (!is_resource($this->connection) || is_null($this->connection)) {
         $this->open();
     }
 }
 public function open()
 {
     if ($this->connected()) {
         return;
     } else {
         $this->close();
     }
     // perform a number of fatality checks, then return gracefully
     if (!function_exists('mysql_connect')) {
         $this->errorNum = 1;
         $this->errorMsg = 'The MySQL adapter "mysql" is not available.';
         return;
     }
     if (!($this->connection = @mysql_connect($this->host, $this->user, $this->password, true))) {
         $this->errorNum = 2;
         $this->errorMsg = 'Could not connect to MySQL';
         return;
     }
     // Set sql_mode to non_strict mode
     mysql_query("SET @@SESSION.sql_mode = '';", $this->connection);
     parent::open();
     // If auto-select is enabled select the given database.
     if ($this->selectDatabase && !empty($this->_database)) {
         $this->select($this->_database);
     }
     $this->setUTF();
 }