8.2.x module.api.php hook_install()
8.0.x module.api.php hook_install()
8.1.x module.api.php hook_install()
8.3.x module.api.php hook_install()
4.7.x install.php hook_install()
5.x install.php hook_install()
6.x install.php hook_install()
7.x system.api.php hook_install()

Install the current version of the database schema.

The hook will be called the first time a module is installed, and the module's schema version will be set to the module's greatest numbered update hook. Because of this, anytime a hook_update_N() is added to the module, this function needs to be updated to reflect the current version of the database schema.

Table names in the CREATE queries should be wrapped with curly braces so that they're prefixed correctly, see db_prefix_tables() for more on this.

Note that since this function is called from a full bootstrap, all functions (including those in modules enabled by the current page request) are available when this hook is called. Use cases could be displaying a user message, or calling a module function necessary for initial setup, etc.

Related topics

16 functions implement hook_install()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

aggregator_install in modules/aggregator/aggregator.install
Implementation of hook_install().
blogapi_install in modules/blogapi/blogapi.install
Implementation of hook_install().
book_install in modules/book/book.install
Implementation of hook_install().
contact_install in modules/contact/contact.install
Implementation of hook_install().
drupal_install in modules/drupal/drupal.install
Implementation of hook_install().

... See full list

4 invocations of hook_install()
drupal_check_module in includes/install.inc
Check a module's requirements.
drupal_check_profile in includes/install.inc
Check a profile's requirements.
drupal_install_modules in includes/install.inc
Calls the install function and updates the system table for a given list of modules.
drupal_install_profile in includes/install.inc
Install a profile (i.e. a set of modules) from scratch. The profile must be verified first using drupal_verify_profile().

File

developer/hooks/install.php, line 125
Documentation for the installation and update system.

Code

function hook_install() {
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_query("CREATE TABLE {event} (
                  nid int(10) unsigned NOT NULL default '0',
                  event_start int(10) unsigned NOT NULL default '0',
                  event_end int(10) unsigned NOT NULL default '0',
                  timezone int(10) NOT NULL default '0',
                  PRIMARY KEY (nid),
                  KEY event_start (event_start)
                ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;"
      );
      break;

    case 'pgsql':
      db_query("CREATE TABLE {event} (
                  nid int NOT NULL default '0',
                  event_start int NOT NULL default '0',
                  event_end int NOT NULL default '0',
                  timezone int NOT NULL default '0',
                  PRIMARY KEY (nid)
                );"
      );
      break;
  }
}