source: trunk/admin/ctrldb.php@ 430

Last change on this file since 430 was 357, checked in by roby, 3 years ago

admin: funzioni di controllo del db e suoi aggiornamenti.

File size: 2.0 KB
Line 
1<?php
2
3include("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;
19foreach ($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;\">&nbsp;&nbsp;&nbsp;&nbsp;Il campo ".$loc." non Ú presente nella tua tabella<br></div>";
48 foreach($ctrrem as $z=>$rem) echo "<div style=\"color:$divcolor;\">&nbsp;&nbsp;&nbsp;&nbsp;Il campo $rem Ú presente solo nella tua tabella, andrebbe eliminato<br></div>";
49 echo "<div style=\"color:$divcolor;\">&nbsp;&nbsp;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
59if(count($tabko))
60 foreach($tabko as $val)
61 echo "<br>Da aggiornare: $val";
62else
63 echo "Tutte le tabelle sono aggiornate.";
64 */
65
66?>
Note: See TracBrowser for help on using the repository browser.