普通网友 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 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。