function db_add_primary_key in Drupal 8
Same name and namespace in other branches
- 6 includes/database.mysql-common.inc \db_add_primary_key()
- 6 includes/database.pgsql.inc \db_add_primary_key()
- 7 includes/database/database.inc \db_add_primary_key()
Adds a primary key to a database table.
Parameters
$table: Name of the table to be altered.
$fields: Array of fields for the primary key.
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 addPrimaryKey() on it. For example, $injected_database->schema()->addPrimaryKey($table, $fields);
See also
https://www.drupal.org/node/2993033
\Drupal\Core\Database\Schema::addPrimaryKey()
Related topics
1 call to db_add_primary_key()
- DatabaseLegacyTest::testDbAddPrimaryKey in core/
tests/ Drupal/ KernelTests/ Core/ Database/ DatabaseLegacyTest.php - Tests deprecation of the db_add_primary_key() function.
File
- core/
includes/ database.inc, line 918 - Core systems for the database layer.
Code
function db_add_primary_key($table, $fields) {
@trigger_error('db_add_primary_key() 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 addPrimaryKey() on it. For example, $injected_database->schema()->addPrimaryKey($table, $fields). See https://www.drupal.org/node/2993033', E_USER_DEPRECATED);
return Database::getConnection()
->schema()
->addPrimaryKey($table, $fields);
}