普通网友 2014-05-07 18:25
浏览 47
已采纳

Dbforge在CodeIgniter中导致错误1064

I have written this piece of code for use with Dbforge in CodeIgniter.

$fields = array(

                    'time_stamp' => array(
                                             'type' => 'STRING',
                                             'constraint' => 9,
                                              'null' => TRUE
                                      ),

                    'curr_property' => array(
                                             'type' => 'INT',
                                             'constraint' => 5, 
                                             'unsigned' => TRUE,
                                             'auto_increment' => TRUE
                                      ),

                    'curr_property_cost' => array(
                                              'type' => 'INT',
                                             'constraint' => 5, 
                                             'unsigned' => TRUE,
                                             'auto_increment' => TRUE
                                      ),

                    'day_property' => array(
                                             'type' => 'INT',
                                             'constraint' => 5, 
                                             'unsigned' => TRUE,
                                             'auto_increment' => TRUE

                                      ),

                    'day_property_cost' => array(
                                             'type' => 'INT',
                                             'constraint' => 5, 
                                             'unsigned' => TRUE,
                                             'auto_increment' => TRUE

                                      ),

                    'curr_solar_generating' => array(
                                              'type' => 'INT',
                                             'constraint' => 5, 
                                             'unsigned' => TRUE,
                                             'auto_increment' => TRUE

                                      ),

                    'curr_solar_export' => array(
                                             'type' => 'INT',
                                             'constraint' => 5, 
                                             'unsigned' => TRUE,
                                             'auto_increment' => TRUE

                                      ),

                    'day_solar_generated' => array(
                                               'type' => 'INT',
                                             'constraint' => 5, 
                                             'unsigned' => TRUE,
                                             'auto_increment' => TRUE

                                      ),

                     'day_solar_export' => array(
                                              'type' => 'INT',
                                             'constraint' => 5, 
                                             'unsigned' => TRUE,
                                             'auto_increment' => TRUE

                                      ),

                    'curr_chan1' => array(  
                                              'type' => 'INT',
                                             'constraint' => 5, 
                                             'unsigned' => TRUE,
                                             'auto_increment' => TRUE
                                      ),

                    'curr_chan2' => array(
                                              'type' => 'INT',
                                             'constraint' => 5, 
                                             'unsigned' => TRUE,
                                             'auto_increment' => TRUE

                                      ),

                    'curr_chan3' => array(
                                              'type' => 'INT',
                                             'constraint' => 5, 
                                             'unsigned' => TRUE,
                                             'auto_increment' => TRUE

                                      ),

                    'day_chan1' => array(
                                              'type' => 'INT',
                                             'constraint' => 5, 
                                             'unsigned' => TRUE,
                                             'auto_increment' => TRUE

                                      ),

                    'day_chan2' => array(
                                               'type' => 'INT',
                                             'constraint' => 5, 
                                             'unsigned' => TRUE,
                                             'auto_increment' => TRUE

                                      ),

                    'day_chan3' => array(
                                             'type' => 'INT',
                                             'constraint' => 5, 
                                             'unsigned' => TRUE,
                                             'auto_increment' => TRUE

                                      )

                );


                $this->dbforge->add_field($fields);

                $this->dbforge->create_table($this->table_name);

I keep on getting the following error

Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'STRING(9) NULL, `curr_property` INT(5) UNSIGNED NOT NULL AUTO_INCREMENT, `curr' at line 2

CREATE TABLE `admin_tmp` ( `time_stamp` STRING(9) NULL, `curr_property` INT(5) UNSIGNED NOT NULL AUTO_INCREMENT, `curr_property_cost` INT(5) UNSIGNED NOT NULL AUTO_INCREMENT, `day_property` INT(5) UNSIGNED NOT NULL AUTO_INCREMENT, `day_property_cost` INT(5) UNSIGNED NOT NULL AUTO_INCREMENT, `curr_solar_generating` INT(5) UNSIGNED NOT NULL AUTO_INCREMENT, `curr_solar_export` INT(5) UNSIGNED NOT NULL AUTO_INCREMENT, `day_solar_generated` INT(5) UNSIGNED NOT NULL AUTO_INCREMENT, `day_solar_export` INT(5) UNSIGNED NOT NULL AUTO_INCREMENT, `curr_chan1` INT(5) UNSIGNED NOT NULL AUTO_INCREMENT, `curr_chan2` INT(5) UNSIGNED NOT NULL AUTO_INCREMENT, `curr_chan3` INT(5) UNSIGNED NOT NULL AUTO_INCREMENT, `day_chan1` INT(5) UNSIGNED NOT NULL AUTO_INCREMENT, `day_chan2` INT(5) UNSIGNED NOT NULL AUTO_INCREMENT, `day_chan3` INT(5) UNSIGNED NOT NULL AUTO_INCREMENT ) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

I have looked for reasons related to the error no but I couldn't find anything related to my problem other than this link. Will be grateful if someone can tell me what is wrong.

  • 写回答

1条回答 默认 最新

  • dongmou1964 2014-05-07 18:26
    关注

    STRING is not a valid data type in MySQL. I think you are looking for CHAR or VARCHAR.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?