function backup_migrate_source_db::switch_db in Backup and Migrate 6.3
Switch to the current database. Pass true to switch back to the previous db.
3 calls to backup_migrate_source_db::switch_db()
- backup_migrate_source_db::backup_to_file in includes/
sources.db.inc - Backup from this source.
- backup_migrate_source_db::get_table_names in includes/
sources.db.inc - Get a list of tables in the database.
- backup_migrate_source_db::restore_from_file in includes/
sources.db.inc - Restore to this source.
File
- includes/
sources.db.inc, line 214 - Functions to handle the direct to database destination.
Class
- backup_migrate_source_db
- A destination type for saving to a database server.
Code
function switch_db($switch_back = FALSE) {
static $db_stack = array(), $db_url_stack = array();
// If switch back is specified, pop the previous db and activate it.
if ($switch_back && $db_stack) {
// Reset the db_url.
$GLOBALS['db_url'] = array_pop($db_url_stack);
// Set the active db to the first one on the stack.
db_set_active(array_pop($db_stack));
return;
}
// If there is a valid DB URL, switch to it.
if ($url = $this
->get_location()) {
// Add the current db_url to the stack.
$db_url_stack[] = $GLOBALS['db_url'];
// Make the db_url into an array if needed.
if (!is_array($GLOBALS['db_url'])) {
$GLOBALS['db_url'] = array(
'default' => $GLOBALS['db_url'],
);
}
// Add the new db to the db_url array.
$GLOBALS['db_url'][$url] = $url;
// Switch to the new db and push the old one on the stack
$db_stack[] = db_set_active($url);
}
}