db_create_table

6 database.inc db_create_table(&$ret, $name, $table)
7 database.inc db_create_table($name, $table)
8 database.inc db_create_table($name, $table)

Creates a new table from a Drupal table definition.

Parameters

$name: The name of the table to create.

$table: A Schema API table definition array.

Related topics

29 calls to db_create_table()

File

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

Code

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

Comments

Example

Here's an example of adding a new table. You first add the table definition to your hook_schema() and this code will get the info from there. Note the doxygen comment is not "Implements hook_update_n" but the same as the untranslated string returned in the function.

<?php
/**
* Add the herp_derp table for the herp module.
*/
function herp_update_7001() {
 
db_create_table('herp_derp', drupal_get_schema_unprocessed('herp', 'herp_derp'));
  return
'Add the herp_derp table for the herp module.';
}
?>

Login or register to post comments