Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Schema.php

function Schema::createTable

Create a new table from a Drupal table definition.

Parameters

$name: The name of the table to create.

$table: A Schema API table definition array.

Throws

\Drupal\Core\Database\SchemaObjectExistsException If the specified table already exists.

\BadMethodCallException When ::createTableSql() is not implemented in the concrete driver class.

1 call to Schema::createTable()
Schema::alterTable in core/modules/sqlite/src/Driver/Database/sqlite/Schema.php
Create a table with a new schema containing the old content.

File

core/lib/Drupal/Core/Database/Schema.php, line 613

Class

Schema
Provides a base implementation for Database Schema.

Namespace

Drupal\Core\Database

Code

public function createTable($name, $table) {
    if ($this->tableExists($name)) {
        throw new SchemaObjectExistsException("Table '{$name}' already exists.");
    }
    $statements = $this->createTableSql($name, $table);
    foreach ($statements as $statement) {
        $this->connection
            ->query($statement);
    }
}
RSS feed
Powered by Drupal