Changeset 362 for trunk/admin/aggiornadb.php
- Timestamp:
- Mar 27, 2022, 7:51:34 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/admin/aggiornadb.php
r361 r362 1 1 <?php 2 2 3 #implementare controllo con: SHOW INDEX FROM tua_tabella WHERE tua_tabella.tua_colonna='nome_colonna'; 3 #imposta il charset su utf8, qualsiasi altro valore per cambiarlo in latin1; 4 $newcs='utf8'; 5 4 6 @require_once("config.php"); 5 7 try{ 6 $dbi = new PDO("mysql:host=$dbhost;charset=latin1", $dbuname, $dbpass, array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION));7 8 $dbi->exec($sql); 9 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 } 10 12 catch(PDOException $e) 11 13 { 12 14 die( $sql . "<br>" . $e->getMessage()); 13 15 } 16 17 14 18 ############### 15 19 function aggiorna($sql,$dbi,$sql2,$num){ … … 95 99 $num=0; 96 100 101 if(controllo($prefix.'_authors','admincomune',++$num)) 102 { 103 $sql="update `".$prefix."_authors` set admincomune='1' where aid='admin'"; 104 $ret=aggiorna($sql,$dbi,'',$num); 105 $sql="update `".$prefix."_authors` set admincomune='0' where aid!='admin'"; 106 $ret=aggiorna($sql,$dbi,'',$num); 107 echo "Aggiornata la tabella dei permessi<br>"; 108 } 109 97 110 if(!controllo($prefix.'_config','versione',++$num)) 98 111 { 99 112 $sql="alter table `".$prefix."_config` change column `Versione` `versione` int(3)"; 113 $ret=aggiorna($sql,$dbi,'',$num); 114 } 115 116 if(!controllo($prefix.'_config','versione',++$num)) 117 { 118 $sql="alter table `".$prefix."_config` change column `Versione` `versione` int(3)"; 119 $ret=aggiorna($sql,$dbi,'',$num); 120 } 121 122 if(!controllo($prefix.'_config','secret',++$num)) 123 { 124 $sql="alter table `".$prefix."_config` DROP `secret`"; 100 125 $ret=aggiorna($sql,$dbi,'',$num); 101 126 } … … 374 399 375 400 echo "<br>Modifica Charset del database<br>"; 376 #$sql="ALTER DATABASE $dbname CHARACTER SET 'utf8' COLLATE 'utf8_general_ci'"; 401 if($newcs=='utf8') { 402 $cset='utf8'; 403 $ccollate='utf8_general_ci'; 404 $preset='latin1'; 405 }else{ 406 $cset='latin1'; 407 $ccollate='latin1_swedish_ci'; 408 $preset='utf8'; 409 } 410 #$sql="ALTER DATABASE $dbname CHARACTER SET '$cset' COLLATE '$ccollate'"; 377 411 #$res = $dbi->prepare("$sql"); 378 412 #$res->execute(); 379 # alter table $table DEFAULT CHARSET=utf8 COLLATE utf8_general_ci 380 $sql="SELECT table_name,column_name,column_default,column_type,is_nullable FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '$dbname' and (character_set_name=' latin1' or collation_name like 'latin%')";413 414 $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%')"; 381 415 $res = $dbi->prepare("$sql"); 382 416 $res->execute(); 383 417 $tab=''; 418 419 384 420 while(list($nometab,$campo,$def,$tipo,$nul)=$res->fetch(PDO::FETCH_NUM)) { 385 421 if($tab!=$nometab){ 386 $sql="alter table $nometab DEFAULT CHARSET= utf8 COLLATE utf8_general_ci";422 $sql="alter table $nometab DEFAULT CHARSET=$cset COLLATE $ccollate"; 387 423 try{ 388 424 $res2 = $dbi->prepare("$sql"); … … 397 433 if($def!='') $default="DEFAULT '$def'"; else $default=''; 398 434 if($nul=='NO') $nullable='NOT NULL'; else $nullable='NULL'; 399 $sql="ALTER TABLE $nometab CHANGE $campo $campo $tipo CHARACTER SET ' utf8' COLLATE 'utf8_general_ci' $nullable $default;";435 $sql="ALTER TABLE $nometab CHANGE $campo $campo $tipo CHARACTER SET '$cset' COLLATE '$ccollate' $nullable $default;"; 400 436 echo "-- $campo<br>"; 401 437 try{ … … 406 442 { 407 443 $default="DEFAULT $def"; 408 $sql="ALTER TABLE $nometab CHANGE $campo $campo $tipo CHARACTER SET ' utf8' COLLATE 'utf8_general_ci' $nullable $default;";444 $sql="ALTER TABLE $nometab CHANGE $campo $campo $tipo CHARACTER SET '$cset' COLLATE '$ccollate' $nullable $default;"; 409 445 try{ 410 446 $res2 = $dbi->prepare("$sql"); … … 417 453 } 418 454 } 419 $sql="SELECT table_name FROM INFORMATION_SCHEMA.tables WHERE TABLE_SCHEMA = '$dbname' and table_collation like ' latin%'";455 $sql="SELECT table_name FROM INFORMATION_SCHEMA.tables WHERE TABLE_SCHEMA = '$dbname' and table_collation like '$preset%'"; 420 456 $res = $dbi->prepare("$sql"); 421 457 $res->execute(); 422 458 $tab=''; 423 459 while(list($nometab)=$res->fetch(PDO::FETCH_NUM)) { 424 $sql="alter table $nometab DEFAULT CHARSET= utf8 COLLATE utf8_general_ci";460 $sql="alter table $nometab DEFAULT CHARSET=$cset COLLATE $ccollate"; 425 461 try{ 426 462 echo "Tabella: $nometab <br>";
Note:
See TracChangeset
for help on using the changeset viewer.