valeur; if($version == 0) { mysql_query("BEGIN TRANSACTION"); creer_db(); initialiser_db(); mysql_query("COMMIT"); $version = 1; } # version 1 -> 2 if ($version == 1) { mysql_query("BEGIN TRANSACTION"); mysql_query("ALTER TABLE participants ADD CONSTRAINT UNIQUE INDEX pseudo_unique (pseudo);"); mysql_query(" CREATE TABLE IF NOT EXISTS periodes ( id mediumint(3) unsigned NOT NULL auto_increment, nom varchar(200) NOT NULL, nom_abrege varchar(20) NOT NULL DEFAULT '', PRIMARY KEY (id) ) ENGINE=InnoDB AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED; "); mysql_query("INSERT INTO periodes (nom, nom_abrege) VALUES ('vendredi soir à samedi', 'v->s')"); mysql_query("INSERT INTO periodes (nom, nom_abrege) VALUES ('samedi à dimanche', 's->d')"); mysql_query("INSERT INTO periodes (nom, nom_abrege) VALUES ('dimanche à lundi', 'd->l')"); mysql_query(" CREATE TABLE IF NOT EXISTS participations ( participant_id mediumint(3) unsigned NOT NULL, periode_id mediumint(3) unsigned NOT NULL, PRIMARY KEY USING BTREE (participant_id, periode_id), KEY FK_periode (periode_id), CONSTRAINT FK_participant_participations FOREIGN KEY (participant_id) REFERENCES participants (id) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT FK_periode_participations FOREIGN KEY (periode_id) REFERENCES periodes (id) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; "); $participations = mysql_query("SELECT participants.id as participant_id, periodes.id as periode_id FROM participants, periodes"); while ($participation = mysql_fetch_object($participations)) { mysql_query(" INSERT INTO participations (participant_id, periode_id) VALUES (".$participation->participant_id.",".$participation->periode_id.")" ); } mysql_query("UPDATE config SET valeur = '2' WHERE nom = 'version'"); mysql_query("INSERT INTO config (nom, valeur) VALUES ('cout_periode', '15')"); mysql_query("INSERT INTO config (nom, valeur) VALUES ('cout_total', '40')"); mysql_query("INSERT INTO config (nom, valeur) VALUES ('nb_max_participant', '25')"); mysql_query("INSERT INTO config (nom, valeur) VALUES ('nb_votes_jeux', '3')"); mysql_query("INSERT INTO config (nom, valeur) VALUES ('inscription_terminees', 'FALSE')"); mysql_query("INSERT INTO config (nom, valeur) VALUES ('pizza_visible', 'FALSE')"); mysql_query("INSERT INTO config (nom, valeur) VALUES ('pizza_peut_commander', 'TRUE')"); mysql_query("COMMIT"); } } update_db(); ?>