0

I have used this file for an extension of mine to add a new table but it doesn't run and gives error. Here is the code for my script.

$installer = $this;

$installer->startSetup();

$installer->run("

-- DROP TABLE IF EXISTS ` magebuzz_testimonial_store`;
CREATE TABLE ` magebuzz_testimonial_store` (
  `testimonial_id` INT(10) UNSIGNED NOT NULL,
    `store_id` VARCHAR(11) NOT NULL,
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Testimonials Store Table';

");

$installer->endSetup();

Can anyone please tell me where am i going wrong with this? Thanks.

  • 1
    Maybe it would be helpful if you could post the error as well... – fmrng Jul 9 '13 at 10:29
  • It just says Error in file: You have a syntax error in your file on line number 4 near ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Testimonials Store Table'' But there is just comment on line number 4 and code starts after that. – jdhaar Jul 9 '13 at 10:35
1

it's because of the comma after the store_id field: It should look like this:

$installer->run("

-- DROP TABLE IF EXISTS `{$installer->getTable('magebuzz_testimonial_store')}`;
CREATE TABLE `{$installer->getTable('magebuzz_testimonial_store')}` (
  `testimonial_id` INT(10) UNSIGNED NOT NULL,
    `store_id` VARCHAR(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Testimonials Store Table';

");

I also added a $installer->getTable() statement around the table name. This is in case you have table a prefix.

  • Thanks. It is working. Just a bit of edit. The curly brace that started near $installer needs to be ended at the end of the same line. – jdhaar Jul 9 '13 at 12:35
  • Right. My bad. sorry. I edited the answer. – Marius Jul 9 '13 at 12:37
0

When running into issues with a MySQL installer script it's always smart to just run the query in PHPMyAdmin for example to see if it returns any errors.

Optionally use PHPMyAdmin or MySQL workbench to create tables and use the export functionality to get the required Query. This way you are sure your query is correct.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.