dsffds54654
dsffds54654
2014-05-07 18:25

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 dongmou1964 7年前

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

    点赞 评论 复制链接分享

相关推荐