GMgKe586q6suSQnyqZLlGCooeWM

Pages

Search

Monday, March 7, 2011

Drupal Module - Creating Table

This file is used as a default table creation when you create a module. May be sometime your module need a sole of table, and this install file will act as the table creator.

Name the file: phone.install

<?php

function phone_install(){
   
    db_insert('dataa')
        ->fields(array(
            'nama' => 'luna maya',
            'age' => 27))
        ->execute();       
}


function phone_schema(){

  $schema['dataa'] = array(
    'description' => 'Data for storing the data',
    'fields' => array(
        'id' => array(
            'type' => 'serial',
            'not null' => TRUE,
            'description' => 'Primary ID',
        ),
        'nama' => array(
            'type' => 'char',
            'length' => 50,
            'not null' => TRUE,
            'default' => 'no name',
        ),
        'age' => array(
            'type' => 'int',
            'not null' => TRUE,
            'default' => 0,
        ),
    ),
    'primary key' => array('id'),
    'indexes' => array(
        'nama' => array('nama'),
        'age' => array('age'),
    ),
 
  );

   
    return $schema;
}

Share/Bookmark

No comments:

Post a Comment