You are here

function backup_migrate_destination_db_mysql::_get_table_structure_sql in Backup and Migrate 8.2

Same name and namespace in other branches
  1. 8.3 includes/destinations.db.mysql.inc \backup_migrate_destination_db_mysql::_get_table_structure_sql()
  2. 6.2 includes/destinations.db.mysql.inc \backup_migrate_destination_db_mysql::_get_table_structure_sql()
  3. 7.3 includes/destinations.db.mysql.inc \backup_migrate_destination_db_mysql::_get_table_structure_sql()
  4. 7.2 includes/destinations.db.mysql.inc \backup_migrate_destination_db_mysql::_get_table_structure_sql()

Get the sql for the structure of the given table.

1 call to backup_migrate_destination_db_mysql::_get_table_structure_sql()
backup_migrate_destination_db_mysql::_backup_db_to_file in includes/destinations.db.mysql.inc
Backup the databases to a file.

File

includes/destinations.db.mysql.inc, line 286
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 _get_table_structure_sql($table) {
  $out = "";
  $result = $this
    ->query("SHOW CREATE TABLE `" . $table['name'] . "`", array(), array(
    'fetch' => PDO::FETCH_ASSOC,
  ));
  foreach ($result as $create) {

    // Lowercase the keys because between Drupal 7.12 and 7.13/14 the default query behavior was changed.
    // See: http://drupal.org/node/1171866
    $create = array_change_key_case($create);
    $out .= "DROP TABLE IF EXISTS `" . $table['name'] . "`;\n";

    // Remove newlines and convert " to ` because PDO seems to convert those for some reason.
    $out .= strtr($create['create table'], array(
      "\n" => ' ',
      '"' => '`',
    ));
    if ($table['auto_increment']) {
      $out .= " AUTO_INCREMENT=" . $table['auto_increment'];
    }
    $out .= ";\n";
  }
  return $out;
}