You are here

function db_rename_table in Drupal 8

Same name and namespace in other branches
  1. 6 includes/database.mysql-common.inc \db_rename_table()
  2. 6 includes/database.pgsql.inc \db_rename_table()
  3. 7 includes/database/database.inc \db_rename_table()

Renames a table.

Parameters

$table: The current name of the table to be renamed.

$new_name: The new name for the table.

Deprecated

in drupal:8.0.0 and is removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call renameTable() on it. For example, $injected_database->schema()->renameTable($table, $new_name);

See also

https://www.drupal.org/node/2993033

\Drupal\Core\Database\Schema::renameTable()

Related topics

1 call to db_rename_table()
DatabaseLegacyTest::testDbRenameTable in core/tests/Drupal/KernelTests/Core/Database/DatabaseLegacyTest.php
Tests deprecation of the db_rename_table() function.

File

core/includes/database.inc, line 772
Core systems for the database layer.

Code

function db_rename_table($table, $new_name) {
  @trigger_error('db_rename_table() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call renameTable() on it. For example, $injected_database->schema()->renameTable($table, $new_name). See https://www.drupal.org/node/2993033', E_USER_DEPRECATED);
  return Database::getConnection()
    ->schema()
    ->renameTable($table, $new_name);
}