function backup_migrate_source_db::_get_db_connection in Backup and Migrate 8.3
Same name and namespace in other branches
- 7.3 includes/sources.db.inc \backup_migrate_source_db::_get_db_connection()
Get the db connection for the specified db.
1 call to backup_migrate_source_db::_get_db_connection()
- backup_migrate_source_db_mysql::_get_db_connection in includes/
sources.db.mysql.inc - Get the db connection for the specified db.
1 method overrides backup_migrate_source_db::_get_db_connection()
- backup_migrate_source_db_mysql::_get_db_connection in includes/
sources.db.mysql.inc - Get the db connection for the specified db.
File
- includes/
sources.db.inc, line 182 - Functions to handle the direct to database destination.
Class
- backup_migrate_source_db
- A destination type for saving to a database server.
Code
function _get_db_connection() {
if (!$this->connection) {
$target = $key = '';
$parts = explode(':', $this
->get_id());
// One of the predefined databases (set in settings.php)
if ($parts[0] == 'db') {
$key = empty($parts[1]) ? 'default' : $parts[1];
$target = empty($parts[2]) ? 'default' : $parts[2];
}
else {
// If the url is specified build it into a connection info array.
if (!empty($this->dest_url)) {
$info = array(
'driver' => empty($this->dest_url['scheme']) ? NULL : $this->dest_url['scheme'],
'host' => empty($this->dest_url['host']) ? NULL : $this->dest_url['host'],
'port' => empty($this->dest_url['port']) ? NULL : $this->dest_url['port'],
'username' => empty($this->dest_url['user']) ? NULL : $this->dest_url['user'],
'password' => empty($this->dest_url['pass']) ? NULL : $this->dest_url['pass'],
'database' => empty($this->dest_url['path']) ? NULL : $this->dest_url['path'],
);
$key = uniqid('backup_migrate_tmp_');
$target = 'default';
Database::addConnectionInfo($key, $target, $info);
}
else {
$key = $target = 'default';
}
}
if ($target && $key) {
$this->connection = Database::getConnection($target, $key);
}
}
return $this->connection;
}