benbox69 Posted March 3, 2011 Share Posted March 3, 2011 Bonjour,J'essaie de créer un module pour ma boutique. Une fonction que je lance pendant l'installation ne fonctionne pas. Elle a pour but de créer les tables nécessaires à mon module.Après l'installation les tables n'apparaissent pas.Pouvez-vous m'aider? //Function called by install - function _createMermozDB() { $db = Db::getInstance(); /* Creates the "product_subscription" table required for storing informations about products available for subscription * Columns Descriptions: id_product_subscription the primary key. * id_product: Stores the product number * id_mermoz_training: Stores the training number * id_mermoz_subject: Stores the subject number * period: Stores the duration of the subscription (in month) */ $r1 = $db->Execute('CREATE TABLE `' . _DB_PREFIX_ . 'product_subscription,` ( `id_product_subscription` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , `id_product` INT NOT NULL , `id_mermoz_training` INT NOT NULL , `id_mermoz_subject` INT NOT NULL , `period` INT NOT NULL , ) ENGINE = MYISAM ' ); /* Creates the "mermoz_training" table required for storing trainings list * Columns Descriptions: id_mermoz_training the primary key. * code: Stores the training code * label: Stores the training title */ $r2 = $db->Execute('CREATE TABLE `' . _DB_PREFIX_ . 'mermoz_training` ( `id_mermoz_training` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , `code` VARCHAR( 8 ) NOT NULL , `label` TEXT NOT NULL , ) ENGINE = MYISAM ' ); // Fills the mermoz_training table $r3 = $db->Execute('INSERT INTO `' . _DB_PREFIX_ . 'mermoz_training` (`id_mermoz_subject`, `code`, `label`) VALUES (\'\', \'atpl\', \'ATPL avion\'), (\'\', \'cpl\', \'CPL Avion\'), (\'\', \'atplh\', \'ATPL hélicoptère IFR\'), (\'\', \'cplh\', \'CPL hélicoptère\'), (\'\', \'atplhvfr\', \'ATPL hélicoptère VFR\'), (\'\', \'ir\', \'IR A/H\')' ); /* Creates the "mermoz_subject" table required for storing subjects list * Columns Descriptions: id_mermoz_subject the primary key. * code: Stores the training code * label: Stores the training title */ $r4 = $db->Execute('CREATE TABLE `' . _DB_PREFIX_ . 'mermoz_subject` ( `id_mermoz_subject` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , `code` VARCHAR( 3 ) NOT NULL , `label` TEXT NOT NULL , ) ENGINE = MYISAM ' ); // Fills the mermoz_subject table $r5 = $db->Execute('INSERT INTO `' . _DB_PREFIX_ . 'mermoz_subject` (`id_mermoz_subject`, `code`, `label`) VALUES (\'\', \'all\', \'Tous les certificats\'), (\'\', \'010\', \'Droit aérien et procédure de la circulation aérienne\'), (\'\', \'021\', \'Connaissance générale des aéronefs - Cellule et systèmes, électricité, motorisation, équipement de secours\'), (\'\', \'022\', \'Connaissance générale des aéronefs : instrumentation\'), (\'\', \'031\', \'Masses et centrage - Avions / Hélicoptères\'), (\'\', \'032\', \'Performances avions\'), (\'\', \'033\', \'Préparation et suivi du vol\'), (\'\', \'034\', \'Performances hélicoptère\'), (\'\', \'040\', \'Performance humaine\'), (\'\', \'050\', \'Météorologie\'), (\'\', \'061\', \'Navigation générale\'), (\'\', \'062\', \'Radionavigation\'), (\'\', \'070\', \'Procédures opérationnelles\'), (\'\', \'081\', \'Principe de vol - Avions\'), (\'\', \'082\', \'Principe de vol - Hélicoptères\'), (\'\', \'091\', \'Communications VFR\'), (\'\', \'092\', \'Communications IFR\')' ); return true; } Merci Link to comment Share on other sites More sharing options...
Broceliande Posted March 3, 2011 Share Posted March 3, 2011 Salut,Je ne vois pas d'anomalies particulière dans ton code, a part que perso je ne spécifie jamais l' ENGINE Tu es bien certain que ta fonction est appelée dans install ? genre function install() { if (!parent::install() OR !$this->_createMermozDB()) return false; return true; } Une suggestion , tu pourrais aussi refactoriser un peu ton code et externaliser ta reqûete de création dans un fichier .sql Tu le charges dans une variable $sql, tu fais un str_replace pour remplacer le préfixe et tu exécutes...Tu peux activer le debug mysql dans la config de presta également pour voir ce qui se passe. Link to comment Share on other sites More sharing options...
benbox69 Posted March 3, 2011 Author Share Posted March 3, 2011 En effet, j'ai supprimé le moteur et cela fonctionne.Sais-tu quel type de retour j'obtiens dans mes variables $r1, $r2 ... cf : mon codeJe pensais m'en servir pour vérifier que les tables étaient bien créées, je m'attends à true en cas de réussite et false en cas de problème, est-ce bien ce genre de retour que j'obtiens?merci pour ton aide Link to comment Share on other sites More sharing options...
Broceliande Posted March 3, 2011 Share Posted March 3, 2011 Absolument , pour preuve un extrait de la classe MySQL : public function Execute($query) { $this->_result = false; if ($this->_link) { $this->_result = mysql_query($query, $this->_link); if (_PS_DEBUG_SQL_) $this->displayMySQLError($query); return $this->_result; } if (_PS_DEBUG_SQL_) $this->displayMySQLError($query); return false; } Edit : (Toute réponse non false étant considérée true ... ) Link to comment Share on other sites More sharing options...
benbox69 Posted March 3, 2011 Author Share Posted March 3, 2011 Merci pour ton aide.J'utilise Prestashop pour la première fois... j'ai l'habitude d'autres framework. Link to comment Share on other sites More sharing options...
Broceliande Posted March 3, 2011 Share Posted March 3, 2011 Merci pour ton aide.J'utilise Prestashop pour la première fois... j'ai l'habitude d'autres framework. On s'y fait très vite. 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