source: trunk/admin/aggiornadb.php@ 363

Last change on this file since 363 was 363, checked in by roby, 2 years ago

Rivista la funzione aggiornadb

File size: 17.7 KB
Line 
1<?php
2
3#imposta il charset su utf8, qualsiasi altro valore per cambiarlo in latin1;
4$newcs='utf8';
5
6@require_once("config.php");
7 try{
8 $dbi = new PDO("mysql:host=$dbhost", $dbuname, $dbpass, array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION));
9 $sql = "use $dbname";
10 $dbi->exec($sql);
11 }
12 catch(PDOException $e)
13 {
14 die( $sql . "<br>" . $e->getMessage());
15 }
16
17
18###############
19function aggiorna($sql,$dbi,$sql2,$num){
20 $ret=0;
21 try{
22 $res = $dbi->prepare("$sql");
23 $res->execute();
24 $ret= 1;
25 }
26 catch(PDOException $e)
27 {
28 $ret=0;
29 echo "<br><span style=\"color: red;\">- Aggiornamento Fallito: $sql</span>";
30 return $ret;
31 }
32
33 if("$sql2"!=""){
34 try{
35 $res = $dbi->prepare("$sql2");
36 $res->execute();
37 $ret=2;
38 }
39 catch(PDOException $e)
40 {
41 $ret=0;
42 echo "<br><span style=\"color: red;\">- Aggiornamento Fallito: $sql2</span>";
43 return $ret;
44 }
45 }
46 echo "<br><span style=\"color: green;\">- Aggiornamento eseguito correttamente</span>";
47 return $ret;
48}
49function aggiorna_index($tab,$ind,$dbi,$sql2,$num){
50 $ret=0;
51 $sqltest="SHOW INDEX FROM `$tab` WHERE KEY_NAME = '$ind'";
52 $res = $dbi->prepare("$sqltest");
53 $res->execute();
54 if($res->rowCount()) {
55 $sql="ALTER TABLE `$tab` DROP INDEX `$ind`";
56 try{
57 $res = $dbi->prepare("$sql");
58 $res->execute();
59 $ret= 1;
60 }
61 catch(PDOException $e)
62 {
63 $ret=0;
64 echo "<br><span style=\"color: red;\">- Tabella: $tab - Indice: $ind - Aggiornamento Fallito: $sql</span>";
65 return $ret;
66 }
67 }
68 if("$sql2"!=""){
69 try{
70 $res = $dbi->prepare("$sql2");
71 $res->execute();
72 $ret=2;
73 }
74 catch(PDOException $e)
75 {
76 $ret=0;
77 echo "<br><span style=\"color: red;\">- Tabella: $tab - Indice: $ind - Aggiornamento Fallito: $sql2</span>";
78 return $ret;
79 }
80 }
81 echo "<br><span style=\"color: green;\">- Tabella: $tab - Indice: $ind - Index aggiornato</span>";
82 return $ret;
83}
84
85
86
87
88function controllo($tabella,$campo,$num)
89{
90 global $dbi, $dbname;
91 $sql="SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '$dbname' AND TABLE_NAME = '$tabella'";
92 $res = $dbi->prepare("$sql");
93 $res->execute();
94 if($res->rowCount() and $campo=='') return 1;
95 while(list($nome)=$res->fetch(PDO::FETCH_NUM)) {if($nome==$campo) { echo "<br>".$num.") Il campo: $campo Ú presente nella tabella: $tabella"; return 1;}}
96 if($campo) echo "<br>$num) Il campo: $campo non Ú presente nella tabella: $tabella";
97 return 0;
98}
99
100$num=0;
101
102if(controllo($prefix.'_authors','admincomune',++$num))
103{
104 $sql="update `".$prefix."_authors` set admincomune='1' where aid='admin'";
105 $ret=aggiorna($sql,$dbi,'',$num);
106 $sql="update `".$prefix."_authors` set admincomune='0' where aid!='admin'";
107 $ret=aggiorna($sql,$dbi,'',$num);
108 echo "<br> La tabella dei permessi Ú stata aggiornata<br>";
109}else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_authors non richiede questo aggiornamento</span><br>";
110
111if(!controllo($prefix.'_config','versione',++$num))
112{
113 $sql="alter table `".$prefix."_config` change column `Versione` `versione` int(3)";
114 $ret=aggiorna($sql,$dbi,'',$num);
115} else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_config non richiede questo aggiornamento</span><br>";
116
117
118if(controllo($prefix.'_config','secret',++$num))
119{
120 $sql="alter table `".$prefix."_config` DROP `secret`";
121 $ret=aggiorna($sql,$dbi,'',$num);
122} else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_config non richiede questo aggiornamento</span><br>";
123
124if(controllo($prefix.'_ele_voti_parziale','data',++$num))
125{
126 $sql="ALTER TABLE `".$prefix."_ele_voti_parziale` CHANGE `data` `data` DATE NOT NULL DEFAULT '1900-01-01'";
127 $ret=aggiorna($sql,$dbi,'',$num);
128 echo "<br>";
129}
130
131if(controllo($prefix.'_ele_rilaff','data',++$num))
132{
133 $sql="ALTER TABLE `".$prefix."_ele_rilaff` CHANGE `data` `data` DATE NOT NULL DEFAULT '1900-01-01'";
134 $ret=aggiorna($sql,$dbi,'',$num);
135 echo "<br>";
136}
137
138if(!controllo($prefix.'_ele_gruppo','num_circ',++$num))
139{
140 $sql="ALTER TABLE `".$prefix."_ele_gruppo` ADD `num_circ` INT(2) UNSIGNED NOT NULL AFTER `id_circ`";
141 $ret=aggiorna($sql,$dbi,'',$num);
142} else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_gruppo non richiede questo aggiornamento</span><br>";
143
144if(!controllo($prefix.'_ele_voti_gruppo','num_gruppo',++$num))
145{
146 $sql="ALTER TABLE `".$prefix."_ele_voti_gruppo` ADD `num_gruppo` INT(2) UNSIGNED NOT NULL AFTER `id_sez`";
147 $ret=aggiorna($sql,$dbi,'',$num);
148} else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_gruppo non richiede questo aggiornamento</span><br>";
149
150if(!controllo($prefix.'_ele_lista','num_gruppo',++$num))
151{
152 $sql="ALTER TABLE `".$prefix."_ele_lista` ADD `num_gruppo` INT(2) UNSIGNED NOT NULL AFTER `id_gruppo`";
153 $ret=aggiorna($sql,$dbi,'',$num);
154}else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_lista non richiede questo aggiornamento</span><br>";
155
156if(!controllo($prefix.'_ele_lista','num_circ',++$num))
157{
158 $sql="ALTER TABLE `".$prefix."_ele_lista` ADD `num_circ` INT(2) UNSIGNED NOT NULL AFTER `id_circ`";
159 $ret=aggiorna($sql,$dbi,'',$num);
160}else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_lista non richiede questo aggiornamento</span><br>";
161
162if(!controllo($prefix.'_ele_operatori','id_circ',++$num))
163{
164 $sql="ALTER TABLE `".$prefix."_ele_operatori` ADD `id_circ` INT(11) NOT NULL DEFAULT 0 AFTER `aid`";
165 $ret=aggiorna($sql,$dbi,'',$num);
166}else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_operatori non richiede questo aggiornamento</span><br>";
167
168if(!controllo($prefix.'_ele_operatori','id_sez',++$num))
169{
170 $sql="ALTER TABLE `".$prefix."_ele_operatori` ADD `id_sez` INT(11) NOT NULL DEFAULT 0 AFTER `id_circ`";
171 $ret=aggiorna($sql,$dbi,'',$num);
172}else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_operatori non richiede questo aggiornamento</span><br>";
173
174if(!controllo($prefix.'_ele_voti_lista','num_lista',++$num))
175{
176 $sql="ALTER TABLE `".$prefix."_ele_voti_lista` ADD `num_lista` INT(2) UNSIGNED NOT NULL AFTER `id_sez`";
177 $ret=aggiorna($sql,$dbi,'',$num);
178}else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_voti_lista non richiede questo aggiornamento</span><br>";
179
180if(!controllo($prefix.'_ele_voti_ref','num_gruppo',++$num))
181{
182 $sql="ALTER TABLE `".$prefix."_ele_voti_ref` ADD `num_gruppo` INT(2) UNSIGNED NOT NULL AFTER `id_sez`";
183 $ret=aggiorna($sql,$dbi,'',$num);
184}else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_voti_ref non richiede questo aggiornamento</span><br>";
185
186if(!controllo($prefix.'_ele_voti_candidati','num_cand',++$num))
187{
188 $sql="ALTER TABLE `".$prefix."_ele_voti_candidati` ADD `num_cand` INT(2) UNSIGNED NOT NULL AFTER `id_sez`";
189 $ret=aggiorna($sql,$dbi,'',$num);
190}else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_voti_candidati non richiede questo aggiornamento</span><br>";
191
192if(!controllo($prefix.'_ele_candidati','num_lista',++$num))
193{
194 $sql="ALTER TABLE `".$prefix."_ele_candidati` ADD `num_lista` INT(2) UNSIGNED NOT NULL AFTER `id_lista`";
195 $ret=aggiorna($sql,$dbi,'',$num);
196}else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_candidati non richiede questo aggiornamento</span><br>";
197
198if(!controllo($prefix.'_ele_sezioni','colore',++$num))
199{
200 $sql="ALTER TABLE `".$prefix."_ele_sezioni` ADD `colore` VARCHAR(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '#FAFAD2' AFTER `solo_lista`";
201 $ret=aggiorna($sql,$dbi,'',$num);
202}else{
203 $sql="ALTER TABLE `".$prefix."_ele_sezioni` CHANGE `colore` `colore` VARCHAR(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '#FAFAD2'";
204 $ret=aggiorna($sql,$dbi,'',$num);
205} echo "<br>";
206
207echo "<br>Aggiornamento per nuovo sistema dei controlli di congruità";
208
209if(!controllo($prefix.'_ele_controlli','id_cons',++$num))
210{
211 $sql="CREATE TABLE if not exists`".$prefix."_ele_controlli` ( `id_cons` INT(11) NOT NULL , `id_sez` INT(11) NOT NULL , `tipo` VARCHAR(10) NOT NULL , `id` INT(11) NOT NULL , INDEX `sezione` (`id_sez`)) ENGINE = MyISAM";
212 echo "<br>".$num.") Creazione tabella dei controlli: ";
213 $ret=aggiorna($sql,$dbi,'',$num);
214}else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_controlli non richiede questo aggiornamento</span><br>";
215
216echo "<br>".++$num.") Eliminazione della vecchia tabella dei controlli: ";
217if(controllo($prefix.'_ele_controllisez','',$num))
218{
219$sql="DROP TABLE if exists `".$prefix."_ele_controllisez`";
220$ret=aggiorna($sql,$dbi,'',$num);
221} else echo "<br><span style=\"color: green;\">- Tabella non presente</span><br>";
222
223echo "<br>".++$num.") Aggiornamento tabella ".$prefix."_ele_voti_gruppo";
224$sql="update `".$prefix."_ele_voti_gruppo` as t1 left join `".$prefix."_ele_gruppo` as t2 on t1.id_gruppo=t2.id_gruppo set t1.num_gruppo=t2.num_gruppo;";
225$ret=aggiorna($sql,$dbi,'',$num);
226
227echo "<br><br>".++$num.") Aggiornamento tabella ".$prefix."_ele_voti_lista";
228$sql="update `".$prefix."_ele_voti_lista` as t1 left join `".$prefix."_ele_lista` as t2 on t1.id_lista=t2.id_lista set t1.num_lista=t2.num_lista;";
229$ret=aggiorna($sql,$dbi,'',$num);
230##############################################
231
232echo "<br><br>".++$num.") Aggiornamento dei valori di default";
233$sql="ALTER TABLE `".$prefix."_ele_gruppo` CHANGE `num_circ` `num_circ` INT(2) UNSIGNED NOT NULL DEFAULT '1';";
234$ret=aggiorna($sql,$dbi,'',$num);
235
236$sql="ALTER TABLE `soraldo_authors` CHANGE `adminsuper` `adminsuper` TINYINT(2) NOT NULL DEFAULT '0';";
237$ret=aggiorna($sql,$dbi,'',$num);
238
239$sql="ALTER TABLE `".$prefix."_ele_lista` CHANGE `num_gruppo` `num_gruppo` INT(2) UNSIGNED NOT NULL DEFAULT '0';";
240$ret=aggiorna($sql,$dbi,'',$num);
241
242$sql="ALTER TABLE `".$prefix."_ele_lista` CHANGE `num_circ` `num_circ` INT(2) UNSIGNED NOT NULL DEFAULT '1';";
243$ret=aggiorna($sql,$dbi,'',$num);
244
245echo "<br><br>".++$num.") Ricostruzione della tabella ".$prefix."_ele_fasce`";
246$sql="DROP TABLE `".$prefix."_ele_fasce`";
247$ret=aggiorna($sql,$dbi,'',$num);
248
249$sql="CREATE TABLE `".$prefix."_ele_fasce` (
250 `id_fascia` int(2) NOT NULL,
251 `abitanti` int(11) NOT NULL,
252 `seggi` int(4) NOT NULL,
253 `id_conf` int(11) DEFAULT 1
254) ENGINE=MyISAM DEFAULT CHARSET 'utf8';";
255
256
257$sql2="INSERT INTO `".$prefix."_ele_fasce` (`id_fascia`, `abitanti`, `seggi`, `id_conf`) VALUES
258(1, 3000, 12, 1),
259(2, 10000, 16, 1),
260(3, 15000, 20, 1),
261(4, 30000, 20, 1),
262(5, 100000, 30, 1),
263(6, 250000, 40, 1),
264(7, 500000, 46, 1),
265(8, 1000000, 50, 1),
266(9, 100000000, 60, 1),
267(1, 3000, 12, 2),
268(2, 10000, 16, 2),
269(3, 15000, 20, 2),
270(4, 30000, 20, 2),
271(5, 100000, 30, 2),
272(6, 250000, 40, 2),
273(7, 500000, 46, 2),
274(8, 1000000, 50, 2),
275(9, 100000000, 60, 2),
276(1, 3000, 9, 3),
277(2, 5000, 9, 3),
278(4, 15000, 16, 3),
279(3, 10000, 12, 3),
280(5, 30000, 16, 3),
281(6, 100000, 24, 3),
282(7, 250000, 32, 3),
283(8, 500000, 36, 3),
284(9, 1000000, 40, 3),
285(10, 100000000, 48, 3),
286(1, 3000, 6, 4),
287(2, 5000, 7, 4),
288(3, 10000, 12, 4),
289(4, 15000, 16, 4),
290(5, 30000, 16, 4),
291(6, 100000, 24, 4),
292(7, 250000, 32, 4),
293(8, 500000, 36, 4),
294(9, 1000000, 40, 4),
295(10, 100000000, 48, 4),
296(1, 3000, 9, 5),
297(2, 5000, 9, 5),
298(3, 10000, 12, 5),
299(4, 15000, 16, 5),
300(5, 30000, 16, 5),
301(6, 100000, 24, 5),
302(7, 250000, 32, 5),
303(8, 500000, 36, 5),
304(9, 1000000, 40, 5),
305(10, 100000000, 48, 5),
306(1, 3000, 6, 6),
307(2, 5000, 7, 6),
308(3, 10000, 10, 6),
309(4, 15000, 16, 6),
310(5, 30000, 16, 6),
311(6, 100000, 24, 6),
312(7, 250000, 32, 6),
313(8, 500000, 36, 6),
314(9, 1000000, 40, 6),
315(10, 100000000, 48, 6),
316(1, 3000, 10, 7),
317(2, 10000, 12, 7),
318(3, 15000, 16, 7),
319(4, 30000, 16, 7),
320(5, 100000, 24, 7),
321(6, 250000, 32, 7),
322(7, 500000, 36, 7),
323(8, 1000000, 40, 7),
324(9, 100000000, 48, 7);";
325$ret=aggiorna($sql,$dbi,$sql2,$num);
326#if(!$ret) echo "<br>".$num++.") Fallito: $sql"; else echo "<br>".$num++.") Aggiornato<br>";
327
328$sql="ALTER TABLE `".$prefix."_ele_fasce`
329 ADD KEY `id_fascia` (`id_fascia`);";
330$ret=aggiorna($sql,$dbi,'',$num);
331#if(!$ret) echo "<br>".$num++.") Fallito: $sql"; else echo "<br>".$num++.") Aggiornato<br>";
332
333
334
335#if(!$ret)
336# echo "<br>".$num++.") Fallito: $sql";
337#elseif ($ret==1)
338# echo "<br>".$num++.") Index eliminato";
339#else
340# echo "<br>".$num++.") Index aggiunto";
341#$sql="ALTER TABLE `".$prefix."_ele_voti_lista` DROP INDEX if exists `id_cons`";
342echo "<br><br>".++$num.") Ricostruzione e aggioramento indici";
343$tab=$prefix."_ele_voti_ref";
344$ind="id_cons";
345# $sql="ALTER TABLE `".$prefix."_ele_voti_ref` DROP INDEX `id_cons`; ";
346$sql2="ALTER TABLE `".$prefix."_ele_voti_ref` ADD INDEX `id_cons` (`id_cons`, `id_gruppo`) USING BTREE";
347$ret=aggiorna_index($tab, $ind,$dbi,$sql2,$num);
348
349$tab=$prefix."_ele_voti_lista";
350$ind="id_cons";
351$sql2="ALTER TABLE `".$prefix."_ele_voti_lista` ADD INDEX `id_cons` (`id_cons`, `id_sez`, `id_lista`) USING BTREE";
352$ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
353
354$tab=$prefix."_ele_voti_gruppo";
355$ind="id_cons";
356#$sql="ALTER TABLE `".$prefix."_ele_voti_gruppo` DROP INDEX if exists `id_cons`";
357$sql2="ALTER TABLE `".$prefix."_ele_voti_gruppo` ADD INDEX `id_cons` (`id_cons`, `id_sez`, `id_gruppo`) USING BTREE";
358$ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
359
360$tab=$prefix."_ele_voti_candidati";
361$ind="id_cons";
362#$sql="ALTER TABLE `".$prefix."_ele_voti_candidati` DROP INDEX if exists `id_cons`";
363$sql2="ALTER TABLE `".$prefix."_ele_voti_candidati` ADD INDEX `id_cons` (`id_cons`, `id_sez`, `id_cand`) USING BTREE";
364$ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
365
366$tab=$prefix."_ele_lista";
367$ind="id_cons";
368#$sql="ALTER TABLE `".$prefix."_ele_lista` DROP INDEX if exists `id_cons`";
369$sql2="ALTER TABLE `".$prefix."_ele_lista` ADD INDEX `id_cons` (`id_cons`, `id_gruppo`) USING BTREE";
370$ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
371
372$tab=$prefix."_ele_lista";
373$ind="PRIMARY";
374#$sql="ALTER TABLE `".$prefix."_ele_lista` DROP INDEX if exists `PRIMARY`";
375$sql2="ALTER TABLE `".$prefix."_ele_lista` ADD PRIMARY KEY (`id_lista`) USING BTREE";
376$ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
377
378$tab=$prefix."_ele_gruppo";
379$ind="id_cons";
380#$sql="ALTER TABLE `".$prefix."_ele_gruppo` DROP INDEX if exists `id_cons`";
381$sql2="ALTER TABLE `".$prefix."_ele_gruppo` ADD INDEX `id_cons` (`id_cons`, `id_circ`) USING BTREE";
382$ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
383
384$tab=$prefix."_ele_gruppo";
385$ind="PRIMARY";
386#$sql="ALTER TABLE `".$prefix."_ele_gruppo` DROP INDEX if exists `PRIMARY`";
387$sql2="ALTER TABLE `".$prefix."_ele_gruppo` ADD PRIMARY KEY (`id_gruppo`) USING BTREE";
388$ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
389
390$tab=$prefix."_ele_candidati";
391$ind="id_cons";
392#$sql="ALTER TABLE `".$prefix."_ele_candidati` DROP INDEX if exists `id_cons`";
393$sql2="ALTER TABLE `".$prefix."_ele_candidati` ADD INDEX `id_cons` (`id_cons`, `id_lista`) USING BTREE";
394$ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
395
396$tab=$prefix."_ele_candidati";
397$ind="PRIMARY";
398#$sql="ALTER TABLE `".$prefix."_ele_candidati` DROP INDEX if exists `PRIMARY`";
399$sql2="ALTER TABLE `".$prefix."_ele_candidati` ADD PRIMARY KEY (`id_cand`) USING BTREE";
400$ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
401
402$tab=$prefix."_ele_consultazione";
403$ind="descrizione";
404#$sql="ALTER TABLE `".$prefix."_ele_consultazione` DROP INDEX if exists `descrizione`";
405$sql2="ALTER TABLE `".$prefix."_ele_consultazione` ADD UNIQUE `descrizione` (`descrizione`(100))";
406$ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
407
408echo "<br><br>".++$num.") Modifica Charset del database";
409if($newcs=='utf8') {
410 $cset='utf8';
411 $ccollate='utf8_general_ci';
412 $preset='latin1';
413}else{
414 $cset='latin1';
415 $ccollate='latin1_swedish_ci';
416 $preset='utf8';
417}
418#$sql="ALTER DATABASE $dbname CHARACTER SET '$cset' COLLATE '$ccollate'";
419#$res = $dbi->prepare("$sql");
420#$res->execute();
421
422$sql="SELECT table_name,column_name,column_default,column_type,is_nullable FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '$dbname' and (character_set_name='$preset' or collation_name like '$preset%')";
423$res = $dbi->prepare("$sql");
424$res->execute();
425$tab='';
426$agg=$res->rowCount();
427
428while(list($nometab,$campo,$def,$tipo,$nul)=$res->fetch(PDO::FETCH_NUM)) {
429 if($tab!=$nometab){
430 $sql="alter table $nometab DEFAULT CHARSET=$cset COLLATE $ccollate";
431 try{
432 $res2 = $dbi->prepare("$sql");
433 $res2->execute();
434 }
435 catch(PDOException $e)
436 {
437 die( $sql . "<br>" . $e->getMessage());
438 }
439 $tab=$nometab; echo "<br><span style=\"color: green;\">- Tabella: $nometab</span>";
440 }
441 if($def!='') $default="DEFAULT '$def'"; else $default='';
442 if($nul=='NO') $nullable='NOT NULL'; else $nullable='NULL';
443 $sql="ALTER TABLE $nometab CHANGE $campo $campo $tipo CHARACTER SET '$cset' COLLATE '$ccollate' $nullable $default;";
444 try{
445 $res2 = $dbi->prepare("$sql");
446 $res2->execute();
447 }
448 catch(PDOException $e)
449 {
450 $default="DEFAULT $def";
451 $sql="ALTER TABLE $nometab CHANGE $campo $campo $tipo CHARACTER SET '$cset' COLLATE '$ccollate' $nullable $default;";
452 try{
453 $res2 = $dbi->prepare("$sql");
454 $res2->execute();
455 }
456 catch(PDOException $e)
457 {
458 die( $sql . "<br>" . $e->getMessage());
459 }
460 }
461 echo "<br><span style=\"color: green;\">-- $campo</span>";
462}
463 $sql="SELECT table_name FROM INFORMATION_SCHEMA.tables WHERE TABLE_SCHEMA = '$dbname' and table_collation like '$preset%'";
464 $res = $dbi->prepare("$sql");
465 $res->execute();
466$tab='';
467if(!$agg) $agg=$res->rowCount();
468while(list($nometab)=$res->fetch(PDO::FETCH_NUM)) {
469 $sql="alter table $nometab DEFAULT CHARSET=$cset COLLATE $ccollate";
470 try{
471 $res2 = $dbi->prepare("$sql");
472 $res2->execute();
473 }
474 catch(PDOException $e)
475 {
476 die( $sql . "<br>" . $e->getMessage());
477 }
478 echo "<br><span style=\"color: green;\">- Tabella: $nometab</span>";
479}
480if(!$agg) echo "<br><span style=\"color: green;\">- Nessuna tabella da aggiornare</span>";
481echo "<br><br>";
482?>
Note: See TracBrowser for help on using the repository browser.