function db_add_index in Drupal 8
Same name and namespace in other branches
- 6 includes/database.mysql-common.inc \db_add_index()
- 6 includes/database.pgsql.inc \db_add_index()
- 7 includes/database/database.inc \db_add_index()
Adds an index.
Parameters
$table: The table to be altered.
$name: The name of the index.
array $fields: An array of field names.
array $spec: The table specification of the table to be altered, as taken from a schema definition. See \Drupal\Core\Database\Schema::addIndex() for how to obtain this specification.
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 addIndex() on it. For example, $injected_database->schema()->addIndex($table, $name, $fields, $spec);
See also
https://www.drupal.org/node/2993033
\Drupal\Core\Database\Schema::addIndex()
Related topics
1 call to db_add_index()
- DatabaseLegacyTest::testDbAddIndex in core/
tests/ Drupal/ KernelTests/ Core/ Database/ DatabaseLegacyTest.php - Tests deprecation of the db_add_index() function.
File
- core/
includes/ database.inc, line 1018 - Core systems for the database layer.
Code
function db_add_index($table, $name, $fields, array $spec) {
@trigger_error('db_add_index() is deprecated in drupal:8.0.x and will be removed in drupal:9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call addIndex() on it. For example, $injected_database->schema()->addIndex($table, $name, $fields, $spec). See https://www.drupal.org/node/2993033', E_USER_DEPRECATED);
Database::getConnection()
->schema()
->addIndex($table, $name, $fields, $spec);
}