Community Documentation

hook_install

5 install.php hook_install()
6 install.php hook_install()
7 system.api.php hook_install()
8 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

▾ 50 functions implement hook_install()

aggregator.install in modules/aggregator/aggregator.install
aggregator_install in modules/aggregator/aggregator.install
Implementation of hook_install().
aggregator_uninstall in modules/aggregator/aggregator.install
Implementation of hook_uninstall().
blogapi.install in modules/blogapi/blogapi.install
blogapi_install in modules/blogapi/blogapi.install
Implementation of hook_install().
blogapi_uninstall in modules/blogapi/blogapi.install
Implementation of hook_uninstall().
book.install in modules/book/book.install
book_install in modules/book/book.install
Implementation of hook_install().
book_uninstall in modules/book/book.install
Implementation of hook_uninstall().
color.install in modules/color/color.install
comment.install in modules/comment/comment.install
contact.install in modules/contact/contact.install
contact_install in modules/contact/contact.install
Implementation of hook_install().
contact_uninstall in modules/contact/contact.install
Implementation of hook_uninstall().
drupal.install in modules/drupal/drupal.install
drupal_install in modules/drupal/drupal.install
Implementation of hook_install().
drupal_uninstall in modules/drupal/drupal.install
Implementation of hook_uninstall().
forum.install in modules/forum/forum.install
forum_install in modules/forum/forum.install
Implementation of hook_install().
forum_uninstall in modules/forum/forum.install
Implementation of hook_uninstall().
hook_uninstall in developer/hooks/install.php
Remove any tables or variables that the module sets.
locale.install in modules/locale/locale.install
locale_install in modules/locale/locale.install
Implementation of hook_install().
locale_uninstall in modules/locale/locale.install
Implementation of hook_uninstall().
module_load_install in includes/module.inc
Load a module's installation hooks.
nodeapi_example.install in developer/examples/nodeapi_example.install
nodeapi_example_install in developer/examples/nodeapi_example.install
Implementation of hook_install().
nodeapi_example_uninstall in developer/examples/nodeapi_example.install
Implementation of hook_uninstall().
node_access_example.install in developer/examples/node_access_example.install
node_access_example_install in developer/examples/node_access_example.install
Implementation of hook_install().
node_access_example_uninstall in developer/examples/node_access_example.install
Implementation of hook_uninstall().
node_example.install in developer/examples/node_example.install
node_example_install in developer/examples/node_example.install
Implementation of hook_install().
node_example_uninstall in developer/examples/node_example.install
Implementation of hook_uninstall().
poll.install in modules/poll/poll.install
poll_install in modules/poll/poll.install
Implementation of hook_install().
poll_uninstall in modules/poll/poll.install
Implementation of hook_uninstall().
profile.install in modules/profile/profile.install
profile_install in modules/profile/profile.install
Implementation of hook_install().
profile_uninstall in modules/profile/profile.install
Implementation of hook_uninstall().
search.install in modules/search/search.install
search_install in modules/search/search.install
Implementation of hook_install().
search_uninstall in modules/search/search.install
Implementation of hook_uninstall().
statistics.install in modules/statistics/statistics.install
statistics_install in modules/statistics/statistics.install
Implementation of hook_install().
statistics_uninstall in modules/statistics/statistics.install
Implementation of hook_uninstall().
system.install in modules/system/system.install
system_install in modules/system/system.install
Implementation of hook_install().
system_modules_uninstall in modules/system/system.module
Builds a form of currently disabled modules.
theme_system_modules_uninstall in modules/system/system.module
Themes a table of currently disabled modules.

File

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

Code

<?php
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;
  }
}
?>
Login or register to post comments