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.

2
  • 1
    Maybe it would be helpful if you could post the error as well... Commented Jul 9, 2013 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. Commented Jul 9, 2013 at 10:35

2 Answers 2

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.

2
  • 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. Commented Jul 9, 2013 at 12:35
  • Right. My bad. sorry. I edited the answer. Commented Jul 9, 2013 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 and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.