hook_schema

Definition

hook_schema()
developer/hooks/install.php, line 140

Description

Define the current version of the database schema.

A Drupal schema definition is an array structure representing one or more tables and their related keys and indexes. A schema is defined by hook_schema() which must live in your module's .install file.

By implementing hook_schema() and specifying the tables your module declares, you can easily create and drop these tables on all supported database engines. You don't have to deal with the different SQL dialects for table creation and alteration of the supported database engines.

See the Schema API Handbook at http://drupal.org/node/146843 for details on schema definition structures.

Return value

A schema definition structure array. For each element of the array, the key is a table name and the value is a table structure definition.

Related topics

Namesort iconDescription
HooksAllow modules to interact with the Drupal core.

Code

<?php
function hook_schema() {
  $schema['mytable1'] = array(
    // specification for mytable1
  );
  $schema['mytable2'] = array(
    // specification for mytable2
  );
  return $schema;
}
?>
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.