0

我创建了一个扩展,当我在其他版本上测试它时,它给了我错误

Error in file: "/var/www/mage_sample/app/code/local/MYD/Module/sql/findyoursize_setup/mysql4-install-0.1.0.php" - SQLSTATE[42000]: Syntax error or access violation: 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 '' at line 1.

当我在 sql 中尝试相同的代码时,它可以工作。任何人都可以帮助解决问题吗?我尝试了很多,现在卡住了。以下是我的安装程序代码:

$installer = $this;

$installer->startSetup();

$installer->run("

 DROP TABLE IF EXISTS {$this->getTable('dimensions')};
CREATE TABLE {$this->getTable('dimensions')} (                            
              `dimension_id` int(11) NOT NULL AUTO_INCREMENT,        
              `label` varchar(250) DEFAULT NULL,                     
              `code` varchar(250) DEFAULT NULL,                      
              PRIMARY KEY (`dimension_id`)                           
            ) ENGINE=InnoDB  DEFAULT CHARSET=latin1;



DROP TABLE IF EXISTS {$this->getTable(`standards`)};
CREATE TABLE {$this->getTable(`standards`)} (                    
            `standards_id` int(10) NOT NULL AUTO_INCREMENT,        
             `name` varchar(250) DEFAULT NULL,                      
             PRIMARY KEY (`standards_id`)                           
           ) ENGINE=InnoDB  DEFAULT CHARSET=latin1;

DROP TABLE IF EXISTS {$this->getTable(`standards_values`)};
CREATE TABLE {$this->getTable(`standards_values`)} (                                                                                                       
                   `standards_id` int(11) DEFAULT NULL,                    
                    `value` varchar(250) DEFAULT NULL,                      
                    `order` int(4) DEFAULT NULL,                            
                    `value_id` int(8) NOT NULL AUTO_INCREMENT,              
                    UNIQUE KEY `value_id` (`value_id`),                     
                    KEY `FK_standards_values` (`standards_id`)              
                  ) ENGINE=InnoDB  DEFAULT CHARSET=latin1              

 insert  into  {$this->getTable('dimensions')}(`dimension_id`,`label`,`code`) values (1,'Chest','chest');
insert  into `dimensions`(`dimension_id`,`label`,`code`) values (2,'Waist','waist');
insert  into `dimensions`(`dimension_id`,`label`,`code`) values (3,'Inseam ','inseam ');
insert  into `dimensions`(`dimension_id`,`label`,`code`) values (4,'Hips','hips');
insert  into `dimensions`(`dimension_id`,`label`,`code`) values (5,'Thigh','thigh');
insert  into `dimensions`(`dimension_id`,`label`,`code`) values (6,'Weight','weight');
insert  into `dimensions`(`dimension_id`,`label`,`code`) values (8,'Neck','neck');");


$installer->endSetup(); 
4

1 回答 1

0
  1. 缺少最后的分号 (;)

如果存在则删除表 {$this->getTable( standards_values)}; 创建表 {$this->getTable( standards_values)} (

               `standards_id` int(11) DEFAULT NULL,                    
                `value` varchar(250) DEFAULT NULL,                      
                `order` int(4) DEFAULT NULL,                            
                `value_id` int(8) NOT NULL AUTO_INCREMENT,              
                UNIQUE KEY `value_id` (`value_id`),                     
                KEY `FK_standards_values` (`standards_id`)              
              ) ENGINE=InnoDB  DEFAULT CHARSET=latin1

应该:

DROP TABLE IF EXISTS {$this->getTable(`standards_values`)};
CREATE TABLE {$this->getTable(`standards_values`)} (                                                                                                       
                   `standards_id` int(11) DEFAULT NULL,                    
                    `value` varchar(250) DEFAULT NULL,                      
                    `order` int(4) DEFAULT NULL,                            
                    `value_id` int(8) NOT NULL AUTO_INCREMENT,              
                    UNIQUE KEY `value_id` (`value_id`),                     
                    KEY `FK_standards_values` (`standards_id`)              
                  ) ENGINE=InnoDB  DEFAULT CHARSET=latin1;
  1. 没有使用 getTable,但这是一个小问题:

插入dimensions( dimension_id, label, code)

应该:

插入 {$this->getTable( dimensions)}( dimension_id, label, code)

祝你好运!

回复问题:

这个查询在我测试过的 MySql 中工作得很好。它实际上只是缺少分号。

如果存在标准,则删除表;创建表标准(

        `standards_id` int(10) NOT NULL AUTO_INCREMENT,        
         `name` varchar(250) DEFAULT NULL,                      
         PRIMARY KEY (`standards_id`)                           
       ) ENGINE=InnoDB  DEFAULT CHARSET=latin1;

如果存在标准值,则删除表;创建表标准值(

               `standards_id` int(11) DEFAULT NULL,                    
                `value` varchar(250) DEFAULT NULL,                      
                `order` int(4) DEFAULT NULL,                            
                `value_id` int(8) NOT NULL AUTO_INCREMENT,              
                UNIQUE KEY `value_id` (`value_id`),                     
                KEY `FK_standards_values` (`standards_id`)              
              ) ENGINE=InnoDB  DEFAULT CHARSET=latin1;
于 2013-08-03T08:19:34.027 回答