0

I am creating a module for Magento. For this I need already inserted data in table. For this I need to write sql/module_setup/mysql4-install-0.1.0.php installer script to insert data from excel or csv to table.

my installer script is like this to create table

$installer = $this;

$installer->startSetup();


$installer->run("

CREATE TABLE `{$this->getTable('module_setup_data')}` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `code` varchar(255),
  `code_type` varchar(255),
  PRIMARY KEY  (`id`),

) ENGINE=InnoDB DEFAULT CHARSET=utf8;

    ");

$installer->endSetup();

Please guide me how to write sql/module_setup/mysql4-install-0.1.0.php installer script to insert query from excel or csv.

1 Answer 1

0

You can install the data in a separate directory called Data in the module directory, You can get the full tutorial on this link for using this method

For reading the data from csv, Magento has provided the class Varien_File_Csv, you can use it and read the data , you will get the data in an array,

For Reading the data from excel, you need to use some Third party Library, which i don't recommend for using only to insert data for one time.

5
  • For module_setup_data table I have not created any model or collection class. $collection = Mage::getModel('module/setup_data')->getCollection() is not working. So, Can you please guide me how can I get value from this table. Thanks buddy for your help
    – mike smith
    Commented Feb 23, 2015 at 6:56
  • There is no module called "module", you need to define model first, the "module" will be replaced by your module name, and setup_data can be any model name associated with the table Commented Feb 23, 2015 at 6:59
  • I have not created any model which is associated with the table
    – mike smith
    Commented Feb 23, 2015 at 7:02
  • You need to create the model, without that you can not do any database interaction, not even the installation of the module Commented Feb 23, 2015 at 7:03
  • Have a look at this link for creating the model Commented Feb 23, 2015 at 7:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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