2

Anything specific I need in the module file?

Install File

function module_install() {

//lets create the school database
$create_table_sql = "CREATE TABLE IF NOT EXISTS `table1` (

id int(11) NOT NULL, principal_name varchar(300) NOT NULL, school_name varchar(300) NOT NULL, address1 varchar(300) NOT NULL, address2 varchar(300) NOT NULL, city varchar(300) NOT NULL, computer_serial_no varchar(300) NOT NULL, state varchar(200) NOT NULL, uid int(200) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1";

db_query($create_table_sql);


//lets create the student database

$create_table_sql = "CREATE TABLE IF NOT EXISTS table2 ( id int(11) NOT NULL, principal_name varchar(300) NOT NULL, school_name varchar(300) NOT NULL, address1 varchar(300) NOT NULL, address2 varchar(300) NOT NULL, city varchar(300) NOT NULL, computer_serial_no varchar(300) NOT NULL, state varchar(200) NOT NULL, uid int(200) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1";

db_query($create_table_sql);

}

/** * _UNINSTALL hook * * This function is run to uninstall the module. * */ function module_uninstall() {

// Delete the DB
db_query("drop table table1");
db_query("drop table table2");

}

Info File Just in Case

; $Id$

name = My Module description = This module deals with blah blah package = Somepackage core = 6.x

version = "6.x-1.0" core = "6.x"

1
  • It seems you are using Drupal 5 code for Drupal 6. Drupal 6 has new database functions that allow you to abstract from such details, and write code that is compatible with all the database engines supported by Drupal. Commented Jun 15, 2010 at 20:22

2 Answers 2

4

You should be using hook_install and hook_schema.

http://api.drupal.org/api/function/hook_schema/6

http://api.drupal.org/api/function/hook_install/6

For installing and uninstalling, hook_schema will make it more consistent and easier to debug, without writing SQL.

Sign up to request clarification or add additional context in comments.

Comments

1

You do not need to write your own DDL queries - use the Schema API instead.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.