Jump to content

[SOLVED] InstallDb() not created in database.


Recommended Posts

Hi, I am creating new module, and i want to create a table in database when i install. Module run oke but table isn't created. my code below, help me.

<?php
/*
* 2007-2013 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
*  @author PrestaShop SA <[email protected]>
*  @copyright  2007-2013 PrestaShop SA
*  @license    http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
*  International Registered Trademark & Property of PrestaShop SA
*/


if (!defined('_PS_VERSION_'))
  exit;
 
class PtsMapi extends Module
{
	public function __construct()
  {
    $this->name = 'ptsmapi';
    $this->tab = 'front_office_features';
    $this->version = 1.0;
    $this->author = 'Minh Tinh';
    $this->need_instance = 0;
 
    parent::__construct();
 
    $this->displayName = $this->l('Prestashop API');
    $this->description = $this->l('List of APIs.');
 
    $this->confirmUninstall = $this->l('Are you sure you want to uninstall?');
 
    if (!Configuration::get('PTS_MAPI_NBR'))       
      $this->warning = $this->l('No name provided');
  	}

  	public function install(){
        if (Shop::isFeatureActive())
        Shop::setContext(Shop::CONTEXT_ALL);
     
        return parent::install() &&
        $this->registerHook('leftColumn') &&            
        $this->registerHook('header') &&
        Configuration::updateValue('PTS_MAPI_NBR', 'my module');
    }
    
    public function uninstall()
    {
      if (!parent::uninstall() ||
        !Configuration::deleteByName('PTS_MAPI_NBR'))
        return false;
      return true;
    }
    
    public function getContent()
	{
	   $output = '<h2>'.$this->displayName.'</h2>'; 
       return $output;      
    }
    
    public function installDB()
	{
		$return = true;
		
		$return &= Db::getInstance()->execute('
			CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'pts_mapi` (
				`id_api` INT UNSIGNED NOT NULL AUTO_INCREMENT,
                `name_api` VARCHAR(20) NOT NULL,
				`text_api` VARCHAR(300) NOT NULL,
				PRIMARY KEY (`id_api`, `name_api`)
			) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8 ;');
		
		return $return;
	}
 }
 

 

Edited by o0ozinkyo0o (see edit history)
Link to comment
Share on other sites

You forget to call the installDB function:

    public function install(){
        if (Shop::isFeatureActive())
        Shop::setContext(Shop::CONTEXT_ALL);
     
        return parent::install() &&
        $this->installDB() &&                        <- ADD THIS LINE!!!!
        $this->registerHook('leftColumn') &&            
        $this->registerHook('header') &&
        Configuration::updateValue('PTS_MAPI_NBR', 'my module');
    }

For example, look in

  /modules/loyalty/loyalty.php

 

Hope this helps,

pascal

Link to comment
Share on other sites

You forget to call the installDB function:

    public function install(){
        if (Shop::isFeatureActive())
        Shop::setContext(Shop::CONTEXT_ALL);
     
        return parent::install() &&
        $this->installDB() &&                        <- ADD THIS LINE!!!!
        $this->registerHook('leftColumn') &&            
        $this->registerHook('header') &&
        Configuration::updateValue('PTS_MAPI_NBR', 'my module');
    }

For example, look in

  /modules/loyalty/loyalty.php

 

Hope this helps,

pascal

ohm. I missed it. And it's work. Thanks your help. 

Link to comment
Share on other sites

×
×
  • Create New...