Changeset 361 for trunk/admin/aggiornadb.php
- Timestamp:
- Mar 17, 2022, 4:12:48 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/admin/aggiornadb.php
r360 r361 98 98 { 99 99 $sql="alter table `".$prefix."_config` change column `Versione` `versione` int(3)"; 100 $ret=aggiorna($sql,$dbi,'',$num); 101 } 102 103 if(!controllo($prefix.'__ele_voti_parziale','data',++$num)) 104 { 105 $sql="ALTER TABLE `".$prefix."_ele_voti_parziale` CHANGE `data` `data` DATE NOT NULL DEFAULT '1900-01-01'"; 106 $ret=aggiorna($sql,$dbi,'',$num); 107 } 108 109 if(!controllo($prefix.'__ele_rilaff','data',++$num)) 110 { 111 $sql="ALTER TABLE `".$prefix."_ele_rilaff` CHANGE `data` `data` DATE NOT NULL DEFAULT '1900-01-01'"; 100 112 $ret=aggiorna($sql,$dbi,'',$num); 101 113 } … … 361 373 $ret=aggiorna_index($tab,$ind,$dbi,$sql2,++$num); 362 374 363 375 echo "<br>Modifica Charset del database<br>"; 376 #$sql="ALTER DATABASE $dbname CHARACTER SET 'utf8' COLLATE 'utf8_general_ci'"; 377 #$res = $dbi->prepare("$sql"); 378 #$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%')"; 381 $res = $dbi->prepare("$sql"); 382 $res->execute(); 383 $tab=''; 384 while(list($nometab,$campo,$def,$tipo,$nul)=$res->fetch(PDO::FETCH_NUM)) { 385 if($tab!=$nometab){ 386 $sql="alter table $nometab DEFAULT CHARSET=utf8 COLLATE utf8_general_ci"; 387 try{ 388 $res2 = $dbi->prepare("$sql"); 389 $res2->execute(); 390 } 391 catch(PDOException $e) 392 { 393 die( $sql . "<br>" . $e->getMessage()); 394 } 395 $tab=$nometab; echo "Tabella: $nometab<br>"; 396 } 397 if($def!='') $default="DEFAULT '$def'"; else $default=''; 398 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;"; 400 echo "-- $campo<br>"; 401 try{ 402 $res2 = $dbi->prepare("$sql"); 403 $res2->execute(); 404 } 405 catch(PDOException $e) 406 { 407 $default="DEFAULT $def"; 408 $sql="ALTER TABLE $nometab CHANGE $campo $campo $tipo CHARACTER SET 'utf8' COLLATE 'utf8_general_ci' $nullable $default;"; 409 try{ 410 $res2 = $dbi->prepare("$sql"); 411 $res2->execute(); 412 } 413 catch(PDOException $e) 414 { 415 die( $sql . "<br>" . $e->getMessage()); 416 } 417 } 418 } 419 $sql="SELECT table_name FROM INFORMATION_SCHEMA.tables WHERE TABLE_SCHEMA = '$dbname' and table_collation like 'latin%'"; 420 $res = $dbi->prepare("$sql"); 421 $res->execute(); 422 $tab=''; 423 while(list($nometab)=$res->fetch(PDO::FETCH_NUM)) { 424 $sql="alter table $nometab DEFAULT CHARSET=utf8 COLLATE utf8_general_ci"; 425 try{ 426 echo "Tabella: $nometab <br>"; 427 $res2 = $dbi->prepare("$sql"); 428 $res2->execute(); 429 } 430 catch(PDOException $e) 431 { 432 die( $sql . "<br>" . $e->getMessage()); 433 } 434 } 435 echo "<br><br>"; 364 436 ?>
Note:
See TracChangeset
for help on using the changeset viewer.