Jump to content

Create SQL table with module


WoW06

Recommended Posts

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 by WoW06 (see edit history)
Link to comment
Share on other sites

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

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 by Eolia (see edit history)
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...