Jump to content

Uninstall function does not work


Recommended Posts

Hi everybody,

 

I'm trying to make a module which will use database. When I install module the table is created in database, but when I uninstall module and try to run query delete table, the module is successfully uninstalled, but the table stile exist in db.

 

Also, when I try to insert something in that table, nothing happens. I can not insert anything.

 

Do you have an idea why is problem to create module with table? Some permissions?

 

This is how my code looks:

 

  public function install()
        {
            if(!parent::install() ||
                !$this->registerHook('displayHome')
            )
                {
                return false;
                }else
                {
                $res = $this->createTables();
 
                return (bool)$res;
                }
        }
 
        public function uninstal()
        {
            if(parent::uninstall())
                {
                $res = $this->deleteTables();
                return (bool)$res;
                }
            return false;
        }
 
        protected function createTables()
        {
            $res = Db::getInstance()->execute('
CREATE TABLE IF NOT EXISTS `category_background_images` (
 `id_category_background_images` int(10) unsigned NOT NULL,
 `id_category` int(10) unsigned NOT NULL,
                            `id_lang` int(10) unsigned NOT NULL,
 `position` int(10) unsigned NOT NULL,
 `image` varchar(255) NOT NULL,
 PRIMARY KEY (`id_category_background_images`,`id_category`)
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=UTF8;
');
 
            return $res;
        }
 
        protected function deleteTables()
        {
            $to_del = new BackgroundImage();
$to_del->delete();
            return Db::getInstance()->execute('
DROP TABLE IF EXISTS `'._DB_PREFIX_.' category_background_images`;
');
        }

 

Thank you!

 

Regards,

 

Natasa.

Link to comment
Share on other sites

I think u should do like this :-

    public function install() 
	{
        $sql = array();
        $sql[] = 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'xyz` (
                  `id_dle` int(10) unsigned NOT NULL AUTO_INCREMENT,
                  `id_product` INT( 11 ) UNSIGNED NOT NULL,
                  `name` VARCHAR( 100 ) NOT NULL,
	           PRIMARY KEY (`id_dle`),
                  UNIQUE  (`name`)
                ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8';
        if (!parent::install() OR !$this->registerHook('hook name') OR
        !$this->registerHook('another hook name') OR !Configuration::updateValue('Module_name', 'my friend') OR
        !$this->runSql($sql)) 
            return FALSE;
        return TRUE;
    }
    public function uninstall() 
	{
        $sql = array();
        $sql[] = 'DROP TABLE IF EXISTS `'._DB_PREFIX_.'xyz`';
        if (!parent::uninstall() OR !$this->runSql($sql)) 
		{
            return FALSE;
        }
		return TRUE;
    }
    public function runSql($sql) 
	{
        foreach ($sql as $s) 
		    if (!Db::getInstance()->Execute($s))
		        return FALSE;
		return TRUE;
    }

After this u can insert or delete any data in ur database.

 

hope it may help u :)

Edited by kishoreunni (see edit history)
  • Like 1
Link to comment
Share on other sites

  • 4 months later...
×
×
  • Create New...