Skip to main content
Explain which parts of the sample code are not necessary for the use case in the question.
Source Link
greg_1_anderson
  • 21.4k
  • 2
  • 38
  • 47

Basically, you want to run some php code to import an SQL database dump from a file. There is code that does this in the implementation of drush sql-sync. It looks like this:

  $options = $global_options + $target_options + array(
    'file' => $destination_dump_path,
    'file-delete' => TRUE,
  );
  $return = drush_invoke_process($destination, 'sql-query', array(), $options, $backend_options);
  if ($return['error_status']) {
    // An error was already logged.
    return FALSE;
  }

You could also call drush sql-sync with appropriate options for a more full-featured solution (e.g. if you want to import a local database to a remote site). For an import to a local site, though, it is more straightforward to simply use the snippet above, which essentially runs drush sql-query --file=/path/to/dump.sql.

n.b. You may simply remove (or make empty) $global_options, $target_options and $backend_options. You should also take of the file-delete flag, unless you really would like Drush to delete your sql dump for you after it has imported it (e.g. for temporary files).

Basically, you want to run some php code to import an SQL database dump from a file. There is code that does this in the implementation of drush sql-sync. It looks like this:

  $options = $global_options + $target_options + array(
    'file' => $destination_dump_path,
    'file-delete' => TRUE,
  );
  $return = drush_invoke_process($destination, 'sql-query', array(), $options, $backend_options);
  if ($return['error_status']) {
    // An error was already logged.
    return FALSE;
  }

You could also call drush sql-sync with appropriate options for a more full-featured solution (e.g. if you want to import a local database to a remote site). For an import to a local site, though, it is more straightforward to simply use the snippet above, which essentially runs drush sql-query --file=/path/to/dump.sql.

Basically, you want to run some php code to import an SQL database dump from a file. There is code that does this in the implementation of drush sql-sync. It looks like this:

  $options = $global_options + $target_options + array(
    'file' => $destination_dump_path,
    'file-delete' => TRUE,
  );
  $return = drush_invoke_process($destination, 'sql-query', array(), $options, $backend_options);
  if ($return['error_status']) {
    // An error was already logged.
    return FALSE;
  }

You could also call drush sql-sync with appropriate options for a more full-featured solution (e.g. if you want to import a local database to a remote site). For an import to a local site, though, it is more straightforward to simply use the snippet above, which essentially runs drush sql-query --file=/path/to/dump.sql.

n.b. You may simply remove (or make empty) $global_options, $target_options and $backend_options. You should also take of the file-delete flag, unless you really would like Drush to delete your sql dump for you after it has imported it (e.g. for temporary files).

Source Link
greg_1_anderson
  • 21.4k
  • 2
  • 38
  • 47

Basically, you want to run some php code to import an SQL database dump from a file. There is code that does this in the implementation of drush sql-sync. It looks like this:

  $options = $global_options + $target_options + array(
    'file' => $destination_dump_path,
    'file-delete' => TRUE,
  );
  $return = drush_invoke_process($destination, 'sql-query', array(), $options, $backend_options);
  if ($return['error_status']) {
    // An error was already logged.
    return FALSE;
  }

You could also call drush sql-sync with appropriate options for a more full-featured solution (e.g. if you want to import a local database to a remote site). For an import to a local site, though, it is more straightforward to simply use the snippet above, which essentially runs drush sql-query --file=/path/to/dump.sql.