1 | <?php
|
---|
2 |
|
---|
3 | include("config.php");
|
---|
4 | try{
|
---|
5 | $dbi = new PDO("mysql:host=$dbhost;charset=latin1", $dbuname, $dbpass, array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION));
|
---|
6 | $sql = "use $dbname";
|
---|
7 | $dbi->exec($sql);
|
---|
8 | }
|
---|
9 | catch(PDOException $e)
|
---|
10 | {
|
---|
11 | echo $sql . "<br>" . $e->getMessage();
|
---|
12 | }
|
---|
13 |
|
---|
14 | $lines = file('./inc/sql/db.sql');
|
---|
15 | $tabko = array();
|
---|
16 |
|
---|
17 | $x=0;
|
---|
18 | $y=0;
|
---|
19 | foreach ($lines as $line_num => $line) {
|
---|
20 | if(!$x) {
|
---|
21 | # $len=strlen($line)-2;
|
---|
22 | $line=chop($line);
|
---|
23 | $nometab = $prefix.substr($line, 1,-1);#echo "LINE: $nometab -- x: $x --<br>";
|
---|
24 | $x=1;
|
---|
25 | continue;
|
---|
26 | }elseif(!$y){
|
---|
27 | $elenco=explode(",", $line);
|
---|
28 | $y=1;
|
---|
29 | $x=0;
|
---|
30 | continue;
|
---|
31 | }else{
|
---|
32 | $x=0;
|
---|
33 | $sql="SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '$dbname' AND TABLE_NAME = '$nometab'";
|
---|
34 | $rest = $dbi->prepare("$sql");
|
---|
35 | $rest->execute(); #echo "SQL: $sql";
|
---|
36 | $line=chop($line); #elimina spazi in fondo alla stringa
|
---|
37 | $remcampi=explode(",", $line);
|
---|
38 | $campi=count($remcampi);
|
---|
39 | $loccampip=$rest->fetchAll();
|
---|
40 | $loccampi=array();
|
---|
41 | foreach($loccampip as $z=>$loc) array_push($loccampi,$loc[0]);
|
---|
42 | $ctrloc=array();
|
---|
43 | $ctrloc=array_diff($remcampi,$loccampi);
|
---|
44 | $ctrrem=array_diff($loccampi,$remcampi);
|
---|
45 | if(count($ctrloc) or count($ctrrem)) {$divcolor="red"; $u=1;} else {$divcolor="green"; $u=0;}
|
---|
46 | echo "Controllo Tabella: $nometab<br>";
|
---|
47 | foreach($ctrloc as $z=>$loc) echo "<div style=\"color:$divcolor;\"> Il campo ".$loc." non Ú presente nella tua tabella<br></div>";
|
---|
48 | foreach($ctrrem as $z=>$rem) echo "<div style=\"color:$divcolor;\"> Il campo $rem Ú presente solo nella tua tabella, andrebbe eliminato<br></div>";
|
---|
49 | echo "<div style=\"color:$divcolor;\"> LA TABELLA $nometab";
|
---|
50 | if($u) echo " DEVE ESSERE AGGIORNATA!"; else echo " E' AGGIORNATA";
|
---|
51 | echo "<br></div>";
|
---|
52 |
|
---|
53 | }
|
---|
54 |
|
---|
55 | }
|
---|
56 |
|
---|
57 | /*
|
---|
58 |
|
---|
59 | if(count($tabko))
|
---|
60 | foreach($tabko as $val)
|
---|
61 | echo "<br>Da aggiornare: $val";
|
---|
62 | else
|
---|
63 | echo "Tutte le tabelle sono aggiornate.";
|
---|
64 | */
|
---|
65 |
|
---|
66 | ?>
|
---|