$m) { $table = "create table if not exists " . self::table($nom_module) . " (uid_page integer"; foreach ($m['attributs'] as $nom => &$attr) { if (!$attr['global']) { $table .= ", $nom varchar(50)"; } } $table .= ")"; self::modify("replace into " . self::table("modules") . " values('" . $nom_module . "')"); self::unbuf_query($table); } self::test(); } public static function test() { // TODO : dans les modules qui proposent un nom_systeme, faire une fonction init_ // Cette fonction sera appellée lors de l'initialisation de la BDD. self::modify("replace into " . self::table("pages") . " values(1, '0', '4', 'true', 'racine', '', 'mGalerieIndex', 'true')"); self::modify("replace into " . self::table("pages") . " values(2, '1', '3', 'true', '', 'periode-1', 'mGaleriePeriode', 'true')"); self::modify("replace into " . self::table("pages") . " set uid_page = 3, date_creation = '0', date_modification = '0', publier = 'true', nom_systeme = '', composant_url = 'periode-2', type = 'mGaleriePeriode', dans_nouveautes = 'false'"); self::modify("replace into " . self::table("liens") . " values(1, 2, 'enfants')"); self::modify("replace into " . self::table("liens") . " values(1, 3, 'enfants')"); self::modify("replace into " . self::table("mGalerieIndex") . " values(1, 'Galerie', 'une galerie')"); self::modify("replace into " . self::table("mGaleriePeriode") . " values(2, 'Periode 1', 'été')"); self::modify("replace into " . self::table("mGaleriePeriode") . " values(3, 'Periode 2', 'hiver')"); } public static function begin_transaction() { self::unbuf_query('begin'); } public static function commit() { self::unbuf_query('commit'); } public static function unbuf_query($q) { debug::info("sql : " . $q . ";"); mysql_unbuffered_query($q . ";", self::get()) or Debug::sqlerror(); } public static function select($q) { debug::info("sql : " . $q); $qres = mysql_query($q, BDD::get()) or Debug::sqlerror(); $ret = array(); while ($row = mysql_fetch_assoc($qres)) { $ret[] = $row; } return $ret; } public static function modify($q) { debug::info("sql : $q;"); mysql_unbuffered_query($q . ";", self::get()) or Debug::sqlerror(); } public static function table($nom) { return Config::get('db_prefixe') . $nom; } public static function close() { if (is_resource(self::$handle)) { self::commit(); mysql_close(self::get()) or Debug::sqlerror(); self::$handle = null; } } } ?>