From 765bcb53aa178808c2eec5502aa5387ba6e1bf68 Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 19 Apr 2011 15:14:17 +0200 Subject: Aufgeräumt und verschoben --- scripts/mysqlGraph.php | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 scripts/mysqlGraph.php (limited to 'scripts/mysqlGraph.php') diff --git a/scripts/mysqlGraph.php b/scripts/mysqlGraph.php new file mode 100644 index 0000000..b9012b2 --- /dev/null +++ b/scripts/mysqlGraph.php @@ -0,0 +1,86 @@ + $data){ + $result = mysql_query("SHOW COLUMNS FROM $tablename"); + while ($row = mysql_fetch_assoc($result)) { + $tables[$tablename][] = $row; + } +} +mysql_free_result($result); +echo "Get Fieldlist from tables ...\n"; +// Prepare dot-string +$b = "\n"; +$str = 'digraph x { + node [shape=record]; + ranksep=3; + size="20,20";'.$b; + +// get all table-fields +foreach($tables as $tablename => $data){ + $str .= $tablename .' [label= "{'; + $array = array(); + $array[] = strtoupper($tablename); + foreach($data as $d){ + $array[] = "<".$d['Field'].">".$d['Field']; + } + $str .= implode("|",$array); + $str .= '}",width=3];'.$b; +} + +echo "Generate the Links ...\n"; +// link the database-items (foreign-keys) +foreach($tables as $tablename1 => $table1){ + foreach($table1 as $field1){ + $f1 = $field1['Field']; + foreach($tables as $tablename2 => $table2){ + foreach($table2 as $field2){ + $f2 = $field2['Field']; + if( $tablename1 != $tablename2 && $f1 == $f2 && strstr($f1,'ID') && "pbs_".str_replace("ID",'',$f1) == $tablename1){ + // Draw lines to tables + $str .= $tablename1 ." -> ".$tablename2.";".$b; + // draw lines to table-items + #$str .= $tablename1.":".$f1 ." -> ".$tablename2.":".$f2 .";".$b; + } + } + } + } +} +$str .= "}"; +echo "Write to file ...\n"; +// Create the dot file +$fp = fopen("mysqlGraph.dot", "w"); +fputs ($fp, $str); +fclose ($fp); +// Generate the image +echo "Generate the image ...\n"; +exec("dot -Tpng mysqlGraph.dot >mysqlGraph.png"); +// delete the dot file +unlink ('mysqlGraph.dot'); +echo "Ready!\n"; -- cgit v1.2.3-55-g7522