Ignore:
Timestamp:
Mar 27, 2022, 7:51:34 PM (3 years ago)
Author:
roby
Message:

Ritocchi e sistemazioni varie di completamento delle mofifiche precedenti

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/aggiornadb.php

    r361 r362  
    11<?php
    22
    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
    46@require_once("config.php");
    57        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         $sql = "use $dbname";
    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    }
    1012        catch(PDOException $e)
    1113        {
    1214            die( $sql . "<br>" . $e->getMessage());
    1315        }
     16
     17
    1418###############
    1519function aggiorna($sql,$dbi,$sql2,$num){
     
    9599$num=0;         
    96100
     101if(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
    97110if(!controllo($prefix.'_config','versione',++$num))
    98111{
    99112        $sql="alter table `".$prefix."_config` change column `Versione` `versione` int(3)";
     113        $ret=aggiorna($sql,$dbi,'',$num);
     114}       
     115
     116if(!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
     122if(!controllo($prefix.'_config','secret',++$num))
     123{
     124        $sql="alter table `".$prefix."_config` DROP `secret`";
    100125        $ret=aggiorna($sql,$dbi,'',$num);
    101126}       
     
    374399
    375400echo "<br>Modifica Charset del database<br>";
    376 #$sql="ALTER DATABASE $dbname CHARACTER SET 'utf8' COLLATE 'utf8_general_ci'";
     401if($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'";
    377411#$res = $dbi->prepare("$sql");
    378412#$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%')";
    381415$res = $dbi->prepare("$sql");
    382416$res->execute();
    383417$tab='';
     418
     419
    384420while(list($nometab,$campo,$def,$tipo,$nul)=$res->fetch(PDO::FETCH_NUM)) {
    385421        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";
    387423                try{
    388424                        $res2 = $dbi->prepare("$sql");
     
    397433        if($def!='') $default="DEFAULT '$def'"; else $default='';
    398434        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;";   
    400436        echo "-- $campo<br>";
    401437        try{
     
    406442                {
    407443                        $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;";   
    409445                        try{
    410446                                        $res2 = $dbi->prepare("$sql");
     
    417453                }
    418454}
    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%'";
    420456 $res = $dbi->prepare("$sql");
    421457 $res->execute();
    422458$tab='';
    423459while(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";
    425461                try{
    426462        echo "Tabella: $nometab <br>";
Note: See TracChangeset for help on using the changeset viewer.