Testing and creating a table

01/06/2016

The objective of this snippet is to show if a table exists in the system and to create one if it does not already exist.


$table_name = 'TABLE_NAME';
$table_schema = drupal_get_schema_unprocessed('MODULE_NAME', $table_name);
if (!db_table_exists($table_name)) {
  db_create_table($table_name, $table_schema);
}