protected function DbDumpCommand::getTableScript

protected DbDumpCommand::getTableScript($table, array $schema, array $data)

The part of the script for each table.

Parameters

string $table: Table name.

array $schema: Drupal schema definition.

array $data: Data for the table.

Return value

string The table create statement, and if there is data, the insert command.

File

core/lib/Drupal/Core/Command/DbDumpCommand.php, line 409

Class

DbDumpCommand
Provides a command to dump the current database to a script.

Namespace

Drupal\Core\Command

Code

protected function getTableScript($table, array $schema, array $data) {
  $output = '';
  $output .= "\$connection->schema()->createTable('" . $table . "', " . Variable::export($schema) . ");\n\n";
  if (!empty($data)) {
    $insert = '';
    foreach ($data as $record) {
      $insert .= "->values(" . Variable::export($record) . ")\n";
    }
    $output .= "\$connection->insert('" . $table . "')\n"
      . "->fields(" . Variable::export(array_keys($schema['fields'])) . ")\n"
      . $insert
      . "->execute();\n\n";
  }
  return $output;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Command!DbDumpCommand.php/function/DbDumpCommand::getTableScript/8.1.x