drupal安装模块的麻烦

时间:2011-09-19 10:20:17

标签: drupal drupal-6

请验证我的下面的代码,我的drupal是D6, 不创建表也不删除表。

<?php
// custom1.install

function custom1_install() {
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_query("CREATE TABLE IF NOT EXISTS block_quiz_customer_ans (
        crid int(30) NOT NULL AUTO_INCREMENT,
        qid int(30) NOT NULL,
        cust_ans varchar(255) NOT NULL,
        cust_ip varchar(255) NOT NULL,
        cust_res_date_time varchar(255) NOT NULL,
        created varchar(50) NOT NULL,
        status tinyint(20) NOT NULL DEFAULT '1',
        PRIMARY KEY (`crid`)
        ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=0;");
      break;
  }
}

function custom1_uninstall() {
  print "This is uninstall";
  drupal_uninstall_schema('block_quiz_customer_ans');
  variable_del('block_quiz_customer_ans');
}

1 个答案:

答案 0 :(得分:2)

对模块的安装文件使用模式而不是mysql查询。

function custom1_install(){
$schema['table_name'] = array(
    'description' => '<description',
    'fields' => array(
      'field_name' => array(
        'description' => '<description>',
        'type' => '<datatype>',
      ),
    ),
    'primary key' => array('<field_name>'),
  );
return $schema;

}

希望这会有所帮助!!