
Drupal is most popular CMS in the world for creating the web application. For custom purpose we need to create the drupal modules. We need the custom tables for creating the drupal. In this article I will tell how you can create the sample drupal module with custom two table. When you activate the drupal module then tables which are defined in the module will be get installed. When you unactive the drupal module tables will get deleted from database.
For creating the drupal module three files are necessary and that as follow:
1. yourmodule.info (you can use your module name
2. yourmodule.install
3. yourmodule.module
First .info file is important and in that file we will put module related information. mymodule.info file has following content.
; $Id$ name = My module description = This module is to test the install feature core = 6.x
For creating custom tables you can use following code in mymodule.install file.
<?php
function mymodule_schema() {
$schema['mymodule_test'] = array(
'description' => t('The base table for saved articles.'),
'fields' => array(
'id' => array(
'description' => t('The primary identifier'),
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE),
'uid' => array(
'description' => t('The user identifier.'),
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0),
'name' => array(
'description' => t('The name.'),
'type' => 'varchar',
'length' => '100',
'not null' => TRUE,
'not null' => TRUE),
),
'primary key' => array('id'),
);
$schema['mymodule_test1'] = array(
'description' => t('The base table for saved articles.'),
'fields' => array(
'id' => array(
'description' => t('The primary identifier'),
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE),
'uid1' => array(
'description' => t('The user identifier.'),
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0),
'name' => array(
'description' => t('The name.'),
'type' => 'varchar',
'length' => '100',
'not null' => TRUE,
'not null' => TRUE),
),
'primary key' => array('id'),
);
return $schema;
}
function mymodule_install() {
// Create my tables.
drupal_install_schema('mymodule');
}
function mymodule_uninstall() {
// Drop my tables.
drupal_uninstall_schema('mymodule');
}
?>
.Module file is most important. In this file you can put the code which for you written the module. Now in this file Now I am giving you the sample menu code. mymodule.module file has following content.
<?php
function mymodule_menu() {
$items['mymodule'] = array(
'title' => 'mymodule View',
'page callback' => 'mymodule_view',
'access arguments' => array('access content'),
);
return $items;
}
function mymodule_view()
{
return 'test';
}
?>
If you have some more doubts then please content me and comment on this article.
Incoming search terms:
- drupal modules create tables
- building drupal page that has tables
- drupal module create table
- Drupal module install not installing Table
- drupal module install script
- function module schema() { $schema[module test] = array( description => t(the base table for saved articles ) fields => array( id => array( description => t(the primary identifier) type => int unsigned => true not null => true) uid =&
- how many table are created with installation of drupal
- how to add the db table in module using drupal
- how to add two tables in drupal 6
- post-installation configuration script drupal modules
- recreate module table drupal
- sample module to create database table in drupal 7
- drupal install module create table sql
- drupal insert table module
- drupal how to create datatables
- create table at install time drupal 7
- create table with module drupal
- creating a install file deupal
- db create table example drupal
- drupal 6 module install not creating the tables






This is the third time I came to your blog, I like your blog very much, hope your more good posts.
Hei, I like this blog, many good information, I want to subscribe it, can anyone help me?
I have custom tables in drupal. How can i create a node using these custome tables.
Type your commenhttp://wordpressapi.com/2010/09/05/create-install-script-drupal-module-create-tables/trackback/t here.
I don’t usually reply to posts but I will in this case, great info…I will bookmark your site. Keep up the good work!
hi, just want to ask. how i will do this in drupal 7.. what is the format..?