Creating Drupal Module Part 1 – Install Package
- April 4th, 2010
- Posted in Drupal
- Write comment
first of all we should know that the name of installing any function should be modulename.install and we wont need
<?php
function mymodule_schema() {
$schema['mytable1'] = array(
// specification for mytable1
);
$schema['mytable2'] = array(
// specification for mytable2
);
return $schema;
}
function mymodule_install() {
// Create my tables.
drupal_install_schema('mymodule');
drupal_set_message(t('The tables created successfully'));
}
function mymodule_uninstall() {
// Drop my tables.
drupal_uninstall_schema('mymodule');
drupal_set_message(t('The tables were removed'));
}
?>
sample of table schema array
$schema['distribution_center'] = array(
‘fields’ => array(
‘vid’ => array(
‘type’ => ‘int’,
‘not null’ => TRUE,
‘description’=> “Log ID”
),
‘nid’=>array(
‘type’=>’int’,
‘not null’=>FALSE,
),
‘fname’=>array(
‘type’=>’text’,
‘not null’=>TRUE,
),
‘lname’=>array(
‘type’=>’text’,
‘not null’=>TRUE,
),
‘address’=> array(
‘type’=>’text’,
‘not null’=>TRUE,
),
‘country’=>array(
‘type’=>’text’,
‘not null’=>TRUE,
),
‘city’=>array(
‘type’=>’text’,
‘not null’=>TRUE,
),
‘phone’=>array(
‘type’=>’text’,
‘not null’=>FALSE,
),
‘mobile’=>array(
‘type’=>’text’,
‘not null’=>FALSE,
),
‘email’=>array(
‘type’=>’text’,
‘not null’=>TRUE,
),
’site’=>array(
‘type’=>’text’,
‘not null’=>TRUE,
),
‘center_attr’=> array(
‘type’=>’text’,
‘not null’=>FALSE,
),
),
‘primary key’ => array(‘vid’)
);
No comments yet.