WoW06 Posted November 1, 2014 Share Posted November 1, 2014 (edited) Hello, I'm developping a module for my store and i have a problem to create sql table when installing the module in my store. Here is my code which manage this : public function installDb() { $return = true; include(dirname(__FILE__).'/sql_install.php'); foreach ($sql as $s) $return &= Db::getInstance()->execute($s); return $return; } public function install() { if(parent::install() == false) return false; return true; if(Shop::isFeatureActive()) Shop::setContext(Shop::CONTEXT_ALL); return parent::instal() && $this->registerHook('leftColum') && $this->registerHook('header') && $this->installDb() && Configuration::updateValue('MYMODULE_NAME', 'my friend'); } Thanks you for your help Edited November 1, 2014 by WoW06 (see edit history) Link to comment Share on other sites More sharing options...
PrestaShopDeveloper Posted November 1, 2014 Share Posted November 1, 2014 1. Nothing goes beyond return true;2. The 2 rows: if (Shop...) are doing exactly nothing. 3. You have not listed your actual SQL code that does the table Check some core module that adds a table - there are a couple of them. Link to comment Share on other sites More sharing options...
WoW06 Posted November 1, 2014 Author Share Posted November 1, 2014 Hello, Thanks you for your answer. My SQL code : $sql= "CREATE TABLE IF NOT EXISTS '"._DB_PREFIX_."mymodule'( 'id_mymodule' INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY , 'title' VARCHAR(256) NOT NULL ) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci; "; Thanks you for your help Link to comment Share on other sites More sharing options...
Eolia Posted November 1, 2014 Share Posted November 1, 2014 (edited) Try this... public function installDb() { include(dirname(__FILE__).'/sql_install.php'); foreach ($sql as $s) if (!Db::getInstance()->execute($s)) return false; return true; } And then : public function install() { if(!parent::install() || !$this->registerHook('leftColum') || !$this->registerHook('header') || !$this->installDb() || !Configuration::updateValue('MYMODULE_NAME', 'my friend')) return false; return true; } Edited November 1, 2014 by Eolia (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now