function backup_migrate_destination_db_mysql::_restore_db_from_file in Backup and Migrate 8.2
Same name and namespace in other branches
- 8.3 includes/destinations.db.mysql.inc \backup_migrate_destination_db_mysql::_restore_db_from_file()
- 6.2 includes/destinations.db.mysql.inc \backup_migrate_destination_db_mysql::_restore_db_from_file()
- 7.3 includes/destinations.db.mysql.inc \backup_migrate_destination_db_mysql::_restore_db_from_file()
- 7.2 includes/destinations.db.mysql.inc \backup_migrate_destination_db_mysql::_restore_db_from_file()
Backup the databases to a file.
Overrides backup_migrate_destination_db::_restore_db_from_file
File
- includes/
destinations.db.mysql.inc, line 186 - Functions to handle the direct to database destination.
Class
- backup_migrate_destination_db_mysql
- A destination type for saving to a database server.
Code
function _restore_db_from_file($file, $settings) {
$num = 0;
if ($file
->open() && ($conn = $this
->_get_db_connection())) {
// Read one line at a time and run the query.
while ($line = $this
->_read_sql_command_from_file($file)) {
if (_backup_migrate_check_timeout()) {
return FALSE;
}
if ($line) {
// Prepeare and exexute the statement instead of the api function to avoid substitution of '{' etc.
$stmt = $conn
->prepare($line);
$stmt
->execute();
$num++;
}
}
// Close the file with fclose/gzclose.
$file
->close();
}
else {
drupal_set_message(t("Unable to open file %file to restore database", array(
"%file" => $file
->filepath(),
)), 'error');
$num = FALSE;
}
return $num;
}