DKA-Dohone Posted November 19, 2018 Share Posted November 19, 2018 Bonsoir à toute la communauté, je suis débutant dans Prestashop (v 1.7.4.3) mais avancé en PHP. Je rencontre depuis quelques jours déjà des difficultés à créer une table dans ma base de données lors de l'installation de mon propre module. le module s'installe par contre convenablement mais pas la table. J'ai essayé plusieurs méthodes rencontrées dans plusieurs forums mais hélas toujours rien. voici ce que je fais actuellement : public function install() { if (parent::install() == false && $this->registerHook('displayHome') == false && $this->installDB() == false && Configuration::updateValue('DATA_CONFIG', array( 'items1' => 'xxxxxxxx', 'items2' => 'Test Shop', 'items3' => 'https://www.facebook.com', 'items4' => 'https://www.google.com', 'items5' => 'https://www.gsm.cm', )) == false) return false; return true; } public function uninstall() { if (!parent::uninstall()) return false; return true; } public function getContent() { if(Tools::isSubmit('submit')) { if (isset($_POST['items1'])) { Configuration::updateValue('DOHONE_CONFIG', array( 'items1' => htmlentities($_POST['items1'], ENT_COMPAT, 'UTF-8'), 'items2' => htmlentities($_POST['items2'], ENT_COMPAT, 'UTF-8'), 'items3' => htmlentities($_POST['items3'], ENT_COMPAT, 'UTF-8'), 'items4' => htmlentities($_POST['items4'], ENT_COMPAT, 'UTF-8'), 'items5' => htmlentities($_POST['items5'], ENT_COMPAT, 'UTF-8'), )); $insertData = Configuration::get('DATA_CONFIG'); Db::getInstance()->insert("tableName", $insertData); } } return $this->display(__FILE__, 'submenu.tpl'); } public function hookdisplayHome($params) { array_push($params, Configuration::get("DATA_CONFIG")); $this->smarty->assign(array( 'params' => $params )); return $this->display(__FILE__, 'mymod.tpl'); } public function installDB() { // Execute module install SQL statements $sql_file = dirname(__FILE__).'/install/install.sql'; if (!$this->loadSQLFile($sql_file)) return false; return true; } et dans le fichier install.sql j'ai ceci: CREATE TABLE IF NOT EXISTS `PREFIX_tableName` `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, `items1` VARCHAR(100) NOT NULL, `items2` VARCHAR(40) NOT NULL, `items3` VARCHAR(128) NOT NULL, `items4` VARCHAR(128) NOT NULL, `items5` VARCHAR(128) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8 AUTO_INCREMENT=1; Que faire svp ? Link to comment Share on other sites More sharing options...
DKA-Dohone Posted November 19, 2018 Author Share Posted November 19, 2018 Merci @ndiaga pour ton intervention mais ça va j'ai trouvé une solution public function install() { if (Shop::isFeatureActive()) Shop::setContext(Shop::CONTEXT_ALL); $sql = "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."tableName`( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, `items1` VARCHAR(100) NOT NULL, `items2` VARCHAR(40) NOT NULL, `items3` VARCHAR(128) NOT NULL, `items4` VARCHAR(128) NOT NULL, `items5` VARCHAR(128) NOT NULL )"; if(!$result=Db::getInstance()->Execute($sql)) return false; if (parent::install() == false && $this->registerHook('displayHome') == false) return false; return true; } 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