8.3.x database.inc db_create_table($name, $table)
8.0.x database.inc db_create_table($name, $table)
8.1.x database.inc db_create_table($name, $table)
8.2.x database.inc db_create_table($name, $table)
8.4.x database.inc db_create_table($name, $table)
6.x database.inc db_create_table(&$ret, $name, $table)
7.x database.inc db_create_table($name, $table)

Creates a new table from a Drupal table definition.

Parameters

string $name: The name of the table to create.

array $table: A Schema API table definition array.

Deprecated

as of Drupal 8.0.x, 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 createTable() on it. For example, $injected_database->schema()->createTable($name, $table);

See also

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

Related topics

8 calls to db_create_table()
drupal_install_schema in core/includes/schema.inc
Creates all tables defined in a module's hook_schema().
SchemaTest::assertFieldAdditionRemoval in core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php
Asserts that a given field can be added and removed from a table.
SchemaTest::assertFieldChange in core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php
Asserts that a field can be changed from one spec to another.
SchemaTest::testIndexLength in core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php
Tests that indexes on string fields are limited to 191 characters on MySQL.
SchemaTest::testSchema in core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php
Tests database interactions.

... See full list

File

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

Code

function db_create_table($name, $table) {
  return Database::getConnection()->schema()->createTable($name, $table);
}

Comments

dahousecat’s picture

Please can we have an example of how to get a database connection injected into your service from the container and get its schema driver?