source: cpc/trunk/project/bin/createQEdump.php @ 2686

Last change on this file since 2686 was 2032, checked in by popeye, 10 years ago

Faire un dump des QE sans jointures

File size: 3.1 KB
Line 
1<?php
2$conf = 'db.inc';
3$config_file = file($conf, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
4
5foreach ($config_file as $vars) {
6  $vars = explode('=', $vars);
7  $var[$vars[0]] = trim($vars[1], '"');
8}
9
10$PASS = explode('-p', $var['MYSQLID']);
11$DBNAME = $var['DBNAME'];
12$DBTABLE = "dump_questions_ecrites";
13$DBUSER = $var['DBNAME'];
14$DBPASS = $PASS[1];
15$HOST = "localhost";
16$DEST = "/home/nosdeputes/www.regardscitoyens.org/telechargement/donnees/";
17
18try {
19  $bdd = new PDO('mysql:host='.$HOST.';dbname='.$DBNAME, $DBUSER, $DBPASS, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
20  $bdd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
21
22  $bdd->query('DROP TABLE IF EXISTS `'.$DBTABLE.'`;
23  CREATE TABLE `'.$DBTABLE.'` (
24  `id` bigint(20) NOT NULL,
25  `slug` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
26  `nom` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
27  `sexe` varchar(8) COLLATE utf8_unicode_ci DEFAULT NULL,
28  `nom_circo` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
29  `num_circo` smallint(2) UNSIGNED DEFAULT NULL,
30  `site_web` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
31  `debut_mandat` date DEFAULT NULL,
32  `fin_mandat` date DEFAULT NULL,
33  `place_hemicycle` smallint(3) UNSIGNED DEFAULT NULL,
34  `url_an` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
35  `profession` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
36  `groupe_acronyme` varchar(8) COLLATE utf8_unicode_ci DEFAULT NULL,
37  `source` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
38  `legislature` smallint(2) UNSIGNED DEFAULT NULL,
39  `numero` bigint(20) DEFAULT NULL,
40  `date` date DEFAULT NULL,
41  `date_cloture` date DEFAULT NULL,
42  `ministere` tinytext COLLATE utf8_unicode_ci,
43  `themes` tinytext COLLATE utf8_unicode_ci,
44  `question` text COLLATE utf8_unicode_ci,
45  `reponse` text COLLATE utf8_unicode_ci,
46  `motif_retrait` tinytext COLLATE utf8_unicode_ci,
47  PRIMARY KEY (`id`),
48  KEY `slug` (`slug`),
49  KEY `nom_circo` (`nom_circo`),
50  KEY `num_circo` (`num_circo`),
51  KEY `profession` (`profession`),
52  KEY `groupe_acronyme` (`groupe_acronyme`),
53  UNIQUE KEY `source` (`source`),
54  KEY `numero` (`numero`),
55  KEY `date` (`date`),
56  KEY `date_cloture` (`date_cloture`),
57  FULLTEXT KEY `ministere` (`ministere`),
58  FULLTEXT KEY `themes` (`themes`),
59  FULLTEXT KEY `question` (`question`),
60  FULLTEXT KEY `motif_retrait` (`motif_retrait`)
61) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ;');
62
63$bdd->query('INSERT INTO `'.$DBTABLE.'` SELECT qe.id, pa.slug, pa.nom, pa.sexe, pa.nom_circo, pa.num_circo, pa.site_web, pa.debut_mandat, pa.fin_mandat, pa.place_hemicycle, pa.url_an, pa.profession, pa.groupe_acronyme,  qe.source, qe.legislature, qe.numero, qe.date, qe.date_cloture, qe.ministere, qe.themes, qe.question, qe.reponse, qe.motif_retrait
64FROM `question_ecrite` qe
65LEFT JOIN `parlementaire` pa
66ON qe.parlementaire_id = pa.id;');
67
68exec('mysqldump '.$var['MYSQLID'].' '.$DBNAME.' '.$DBTABLE.' | gzip -v > '.$DEST.$DBTABLE.'.sql.gz');
69
70$bdd->query('DROP TABLE IF EXISTS `'.$DBTABLE.'`;');
71}
72catch (Exception $error) {
73  fprintf(STDERR, 'Error with '.$DBTABLE.'. Msg : '.$error->getMessage()."\"\n");
74}
75?>
Note: See TracBrowser for help on using the repository browser.