-- phpMyAdmin SQL Dump -- version 4.6.5.2 -- https://www.phpmyadmin.net/ -- -- Host: 127.0.0.1 -- Generation Time: Nov 22, 2018 at 09:39 PM -- Server version: 10.1.21-MariaDB -- PHP Version: 7.1.1 SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; SET time_zone = "+00:00"; /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8mb4 */; -- -- Database: `dietetique_2` -- -- -------------------------------------------------------- -- -- Table structure for table `access_token` -- CREATE TABLE `access_token` ( `id` int(11) NOT NULL, `id_compte` int(11) NOT NULL, `selector` char(16) COLLATE utf8mb4_unicode_ci NOT NULL, `token` char(64) COLLATE utf8mb4_unicode_ci NOT NULL, `expires` datetime NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- -- Table structure for table `categorie` -- CREATE TABLE `categorie` ( `id_categorie` int(11) NOT NULL, `nom` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=COMPACT; -- -- Dumping data for table `categorie` -- INSERT INTO `categorie` (`id_categorie`, `nom`) VALUES (1, 'Fruits et L?gumes'), (2, 'Viandes'), (3, 'é'); -- -------------------------------------------------------- -- -- Table structure for table `commandes` -- CREATE TABLE `commandes` ( `id_commande` int(11) NOT NULL, `id_compte` int(11) NOT NULL, `date` datetime NOT NULL, `status` char(1) COLLATE utf8mb4_bin NOT NULL, `prix_total` decimal(5,3) NOT NULL, `trace_paiement` int(11) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=COMPACT; -- -- Triggers `commandes` -- DELIMITER $$ CREATE TRIGGER `tai_commandes` AFTER INSERT ON `commandes` FOR EACH ROW begin declare v_nom varchar(255); declare v_prenom varchar(255); declare v_courriel varchar(255); select c.nom, c.prenom, c.courriel into v_nom, v_prenom, v_courriel from comptes c where c.id_compte = new.id_compte; insert into historiquecommande values (0, new.id_commande, new.id_compte, v_nom, v_prenom, v_courriel, new.date, new.status, new.prix_total, new.trace_paiement); end $$ DELIMITER ; -- -------------------------------------------------------- -- -- Table structure for table `commandesproduits` -- CREATE TABLE `commandesproduits` ( `id_commande` int(11) NOT NULL, `id_produit` int(11) NOT NULL, `quantite` int(11) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -- Triggers `commandesproduits` -- DELIMITER $$ CREATE TRIGGER `tai_commandesproduit` AFTER INSERT ON `commandesproduits` FOR EACH ROW begin declare v_nom varchar(255); declare v_description varchar(1024); declare v_marque varchar(255); declare v_achatmin varchar(255); declare v_economie varchar(255); declare v_unite varchar(255); declare v_format varchar(255); declare v_limite varchar(255); declare v_categorie varchar(255); select p.nom, p.description, p.marque, p.achat_minimum, p.economie, p.unite, f2.nom, p.limite_achat, c2.nom into v_nom, v_description, v_marque, v_achatmin, v_economie, v_unite, v_format, v_limite, v_categorie from produits p inner join format f2 on p.format = f2.id_format inner join categorie c2 on p.categorie = c2.id_categorie where p.id_produit = new.id_produit; insert into historiquecommandeproduit values ((select id_historique from historiquecommande hc where hc.id_commande = new.id_commande), new.id_produit, v_nom, v_description, v_marque, v_achatmin, v_limite, v_economie, v_unite, v_format, v_categorie, new.quantite); end $$ DELIMITER ; -- -------------------------------------------------------- -- -- Table structure for table `commentaires` -- CREATE TABLE `commentaires` ( `id_commentaire` int(11) NOT NULL, `id_compte` int(11) NOT NULL, `date` datetime NOT NULL, `commentaire` varchar(2048) CHARACTER SET latin1 NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- -- Table structure for table `comptes` -- CREATE TABLE `comptes` ( `id_compte` int(11) NOT NULL, `courriel` varchar(255) CHARACTER SET latin1 NOT NULL, `password` varchar(255) CHARACTER SET latin1 NOT NULL, `nom` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `prenom` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `telephone` varchar(30) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `type` char(1) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'U' ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -- Dumping data for table `comptes` -- INSERT INTO `comptes` (`id_compte`, `courriel`, `password`, `nom`, `prenom`, `telephone`, `type`) VALUES (14, 'anthonyrobert1997@hotmail.fr', '$2y$10$aarrTJd0XPxxsNwowXxA5evKxEk7IcyTnlMvhhgO5UmyFCTptcHvy', 'Robert', 'Anthony', '8199447206', 'U'), (15, 'anthonyrobert1997@hotmail.fre', '$2y$10$wpL.s6uzQ1vFm6bqL.Sp.OCk/nG6zTPQdy0nqW1xQXdhcXYYNkEBe', 'Georges', 'Anthony', '8199447206', 'B'), (16, 'admin@admin.com', '$2y$10$.mB/c0ntseE6/FtaFkZ3n.rze9Bt7vEGi7A0sHtZZnCV3BG1yye6K', 'Admin', 'Admin', '8193761721', 'A'), (17, 'test@test.com', '$2y$10$Lujrvd4qbHLSROCL9KlVEOA7a26n/dmoYPB343rqxMzKctcoD55eq', 'Lacerte', 'jeremy', '8199999999', 'U'); -- -- Triggers `comptes` -- DELIMITER $$ CREATE TRIGGER `tai_comptes` AFTER INSERT ON `comptes` FOR EACH ROW insert into panier values(NEW.id_compte, null, null) $$ DELIMITER ; DELIMITER $$ CREATE TRIGGER `tbd_comptes` BEFORE DELETE ON `comptes` FOR EACH ROW delete from panier where panier.id_compte = OLD.id_compte $$ DELIMITER ; -- -------------------------------------------------------- -- -- Table structure for table `configuration` -- CREATE TABLE `configuration` ( `cle` varchar(255) CHARACTER SET latin1 NOT NULL, `valeur` varchar(4096) CHARACTER SET latin1 NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- -- Table structure for table `datescommandes` -- CREATE TABLE `datescommandes` ( `date_debut` datetime NOT NULL, `date_fin` datetime NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- -- Table structure for table `datespaiements` -- CREATE TABLE `datespaiements` ( `date_debut` datetime NOT NULL, `date_fin` datetime NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- -- Table structure for table `format` -- CREATE TABLE `format` ( `id_format` int(11) NOT NULL, `nom` varchar(255) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -- -- Dumping data for table `format` -- INSERT INTO `format` (`id_format`, `nom`) VALUES (1, 'kg'); -- -------------------------------------------------------- -- -- Table structure for table `fournisseurs` -- CREATE TABLE `fournisseurs` ( `id_fournisseur` int(11) NOT NULL, `nom` varchar(255) CHARACTER SET latin1 NOT NULL, `adresse` varchar(1024) CHARACTER SET latin1 NOT NULL, `telephone` varchar(30) COLLATE utf8mb4_unicode_ci DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -- Dumping data for table `fournisseurs` -- INSERT INTO `fournisseurs` (`id_fournisseur`, `nom`, `adresse`, `telephone`) VALUES (2, 'Metro', '123 lol', NULL); -- -------------------------------------------------------- -- -- Table structure for table `historiquecommande` -- CREATE TABLE `historiquecommande` ( `id_historique` int(11) NOT NULL, `id_commande` int(11) DEFAULT NULL, `id_compte` int(11) DEFAULT NULL, `c_nom` varchar(255) DEFAULT NULL, `c_prenom` varchar(255) DEFAULT NULL, `c_courriel` varchar(255) DEFAULT NULL, `date` datetime DEFAULT NULL, `status` char(1) DEFAULT NULL, `prix_total` decimal(10,2) DEFAULT NULL, `trace_paiement` int(11) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -- -------------------------------------------------------- -- -- Table structure for table `historiquecommandeproduit` -- CREATE TABLE `historiquecommandeproduit` ( `id_historique` int(11) DEFAULT NULL, `id_produit` int(11) DEFAULT NULL, `p_nom` varchar(255) DEFAULT NULL, `p_description` varchar(1024) DEFAULT NULL, `p_marque` varchar(255) DEFAULT NULL, `p_commandemin` int(11) DEFAULT NULL, `p_limiteachat` int(11) DEFAULT NULL, `p_economie` varchar(255) DEFAULT NULL, `p_unite` varchar(255) DEFAULT NULL, `p_format` varchar(255) DEFAULT NULL, `p_categorie` varchar(255) DEFAULT NULL, `quantite` int(11) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -- -------------------------------------------------------- -- -- Table structure for table `panier` -- CREATE TABLE `panier` ( `id_compte` int(11) NOT NULL, `id_produit` int(11) DEFAULT NULL, `quantite` int(11) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- -- Table structure for table `produits` -- CREATE TABLE `produits` ( `id_produit` int(11) NOT NULL, `nom` varchar(255) CHARACTER SET latin1 NOT NULL, `description` varchar(1024) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `marque` varchar(255) CHARACTER SET latin1 NOT NULL, `achat_minimum` int(10) NOT NULL, `economie` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `image_produit` varchar(1024) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `valeur_nutritive` varchar(1024) CHARACTER SET latin1 DEFAULT NULL, `format` int(11) NOT NULL, `unite` varchar(15) CHARACTER SET latin1 NOT NULL, `limite_achat` int(11) DEFAULT NULL, `categorie` int(11) NOT NULL, `id_compte` int(11) DEFAULT NULL, `status` char(1) CHARACTER SET latin1 NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- -- Table structure for table `produitsfournisseurs` -- CREATE TABLE `produitsfournisseurs` ( `id_produit` int(11) NOT NULL, `id_fournisseur` int(11) NOT NULL, `prix` decimal(10,2) NOT NULL, `economie` decimal(4,2) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- -- Table structure for table `tracepaiements` -- CREATE TABLE `tracepaiements` ( `id_paiement` int(11) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- -- Stand-in structure for view `v_commande` -- (See below for the actual view) -- CREATE TABLE `v_commande` ( `id_historique` int(11) ,`id_commande` int(11) ,`id_compte` int(11) ,`c_nom` varchar(255) ,`c_prenom` varchar(255) ,`c_courriel` varchar(255) ,`date` datetime ,`status` char(1) ,`prix_total` decimal(10,2) ,`trace_paiement` int(11) ); -- -------------------------------------------------------- -- -- Structure for view `v_commande` -- DROP TABLE IF EXISTS `v_commande`; CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v_commande` AS select `historiquecommande`.`id_historique` AS `id_historique`,`historiquecommande`.`id_commande` AS `id_commande`,`historiquecommande`.`id_compte` AS `id_compte`,`historiquecommande`.`c_nom` AS `c_nom`,`historiquecommande`.`c_prenom` AS `c_prenom`,`historiquecommande`.`c_courriel` AS `c_courriel`,`historiquecommande`.`date` AS `date`,`historiquecommande`.`status` AS `status`,`historiquecommande`.`prix_total` AS `prix_total`,`historiquecommande`.`trace_paiement` AS `trace_paiement` from `historiquecommande` ; -- -- Indexes for dumped tables -- -- -- Indexes for table `access_token` -- ALTER TABLE `access_token` ADD PRIMARY KEY (`id`); -- -- Indexes for table `categorie` -- ALTER TABLE `categorie` ADD PRIMARY KEY (`id_categorie`); -- -- Indexes for table `commandes` -- ALTER TABLE `commandes` ADD PRIMARY KEY (`id_commande`,`id_compte`), ADD KEY `Commandes_fk0` (`id_compte`), ADD KEY `Commandes_fk1` (`trace_paiement`); -- -- Indexes for table `commandesproduits` -- ALTER TABLE `commandesproduits` ADD PRIMARY KEY (`id_commande`,`id_produit`), ADD KEY `CommandesProduits_fk1` (`id_produit`); -- -- Indexes for table `commentaires` -- ALTER TABLE `commentaires` ADD PRIMARY KEY (`id_commentaire`,`id_compte`), ADD KEY `Commentaires_fk0` (`id_compte`); -- -- Indexes for table `comptes` -- ALTER TABLE `comptes` ADD PRIMARY KEY (`id_compte`), ADD KEY `id_compte` (`id_compte`); -- -- Indexes for table `configuration` -- ALTER TABLE `configuration` ADD PRIMARY KEY (`cle`); -- -- Indexes for table `datescommandes` -- ALTER TABLE `datescommandes` ADD PRIMARY KEY (`date_debut`,`date_fin`); -- -- Indexes for table `datespaiements` -- ALTER TABLE `datespaiements` ADD PRIMARY KEY (`date_debut`,`date_fin`); -- -- Indexes for table `format` -- ALTER TABLE `format` ADD PRIMARY KEY (`id_format`), ADD KEY `id_format` (`id_format`); -- -- Indexes for table `fournisseurs` -- ALTER TABLE `fournisseurs` ADD PRIMARY KEY (`id_fournisseur`); -- -- Indexes for table `historiquecommande` -- ALTER TABLE `historiquecommande` ADD PRIMARY KEY (`id_historique`); -- -- Indexes for table `historiquecommandeproduit` -- ALTER TABLE `historiquecommandeproduit` ADD KEY `historiquecommandeproduit_id_historique_index` (`id_historique`); -- -- Indexes for table `panier` -- ALTER TABLE `panier` ADD PRIMARY KEY (`id_compte`) USING BTREE, ADD KEY `Panier_fk0` (`id_produit`); -- -- Indexes for table `produits` -- ALTER TABLE `produits` ADD PRIMARY KEY (`id_produit`), ADD KEY `Produits_fk0` (`categorie`), ADD KEY `Produits_fk1` (`id_compte`), ADD KEY `format` (`format`); -- -- Indexes for table `produitsfournisseurs` -- ALTER TABLE `produitsfournisseurs` ADD PRIMARY KEY (`id_produit`,`id_fournisseur`), ADD KEY `ProduitsFournisseurs_fk1` (`id_fournisseur`); -- -- Indexes for table `tracepaiements` -- ALTER TABLE `tracepaiements` ADD PRIMARY KEY (`id_paiement`); -- -- AUTO_INCREMENT for dumped tables -- -- -- AUTO_INCREMENT for table `access_token` -- ALTER TABLE `access_token` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT; -- -- AUTO_INCREMENT for table `categorie` -- ALTER TABLE `categorie` MODIFY `id_categorie` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4; -- -- AUTO_INCREMENT for table `commandes` -- ALTER TABLE `commandes` MODIFY `id_commande` int(11) NOT NULL AUTO_INCREMENT; -- -- AUTO_INCREMENT for table `commentaires` -- ALTER TABLE `commentaires` MODIFY `id_commentaire` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2; -- -- AUTO_INCREMENT for table `comptes` -- ALTER TABLE `comptes` MODIFY `id_compte` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=18; -- -- AUTO_INCREMENT for table `format` -- ALTER TABLE `format` MODIFY `id_format` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2; -- -- AUTO_INCREMENT for table `fournisseurs` -- ALTER TABLE `fournisseurs` MODIFY `id_fournisseur` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3; -- -- AUTO_INCREMENT for table `historiquecommande` -- ALTER TABLE `historiquecommande` MODIFY `id_historique` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2; -- -- AUTO_INCREMENT for table `produits` -- ALTER TABLE `produits` MODIFY `id_produit` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=6; -- -- AUTO_INCREMENT for table `tracepaiements` -- ALTER TABLE `tracepaiements` MODIFY `id_paiement` int(11) NOT NULL AUTO_INCREMENT; -- -- Constraints for dumped tables -- -- -- Constraints for table `commandes` -- ALTER TABLE `commandes` ADD CONSTRAINT `Commandes_fk0` FOREIGN KEY (`id_compte`) REFERENCES `comptes` (`id_compte`), ADD CONSTRAINT `Commandes_fk1` FOREIGN KEY (`trace_paiement`) REFERENCES `tracepaiements` (`id_paiement`); -- -- Constraints for table `commandesproduits` -- ALTER TABLE `commandesproduits` ADD CONSTRAINT `CommandesProduits_fk0` FOREIGN KEY (`id_commande`) REFERENCES `commandes` (`id_commande`), ADD CONSTRAINT `CommandesProduits_fk1` FOREIGN KEY (`id_produit`) REFERENCES `produits` (`id_produit`); -- -- Constraints for table `commentaires` -- ALTER TABLE `commentaires` ADD CONSTRAINT `Commentaires_fk0` FOREIGN KEY (`id_compte`) REFERENCES `comptes` (`id_compte`); -- -- Constraints for table `historiquecommandeproduit` -- ALTER TABLE `historiquecommandeproduit` ADD CONSTRAINT `historiquecommandeproduit__fk` FOREIGN KEY (`id_historique`) REFERENCES `historiquecommande` (`id_historique`); -- -- Constraints for table `panier` -- ALTER TABLE `panier` ADD CONSTRAINT `Panier_fk0` FOREIGN KEY (`id_produit`) REFERENCES `produits` (`id_produit`), ADD CONSTRAINT `panier_ibfk_1` FOREIGN KEY (`id_compte`) REFERENCES `comptes` (`id_compte`); -- -- Constraints for table `produits` -- ALTER TABLE `produits` ADD CONSTRAINT `Format_fk2` FOREIGN KEY (`format`) REFERENCES `format` (`id_format`), ADD CONSTRAINT `Produits_fk0` FOREIGN KEY (`categorie`) REFERENCES `categorie` (`id_categorie`), ADD CONSTRAINT `Produits_fk1` FOREIGN KEY (`id_compte`) REFERENCES `comptes` (`id_compte`); -- -- Constraints for table `produitsfournisseurs` -- ALTER TABLE `produitsfournisseurs` ADD CONSTRAINT `ProduitsFournisseurs_fk0` FOREIGN KEY (`id_produit`) REFERENCES `produits` (`id_produit`), ADD CONSTRAINT `ProduitsFournisseurs_fk1` FOREIGN KEY (`id_fournisseur`) REFERENCES `fournisseurs` (`id_fournisseur`); /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;