You are here

function backup_migrate_restore_db_from_file_mysql in Backup and Migrate 8.2

Restore the db from a valid backup file.

File

includes/db.mysql.inc, line 43

Code

function backup_migrate_restore_db_from_file_mysql($file, $settings) {
  $num = 0;
  if ($file
    ->open()) {

    // Read one line at a time and run the query.
    while ($line = $file
      ->read()) {
      if (_backup_migrate_check_timeout()) {
        return FALSE;
      }
      $line = trim($line);
      if ($line) {

        // Use the helper instead of the api function to avoid substitution of '{' etc.
        Database::getConnection()
          ->prepare($line)
          ->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;
}