Menu

[r47]: / mysql_diff.php  Maximize  Restore  History

Download this file

56 lines (52 with data), 1.4 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/php
<?php
require("../html/util.php");
$tables=array ();
$tabnr=0;
$new_db="generator_new";
$new = new MySQL_class;
$new->Setup("root","ditismijndb","localhost",$new_db);
$new->Create($new_db);
$old_db="generator";
$old = new MySQL_class;
$old->Setup("root","ditismijndb","localhost",$old_db);
$old->Create($old_db);
$new->Query("SHOW TABLE STATUS FROM `$new_db`");
for($i=0; $i<$new->rows;$i++) {
$new->Fetch($i);
$table=$new->data[Name];
echo "--\n-- Table: $table\n--\n";
$old->Query("SHOW TABLE STATUS FROM `$old_db` LIKE '$table';");
if ($old->rows==0) {
echo "CREATE TABLE `$table`;\n";
} else {
$old->Fetch(0);
if ($old->data[Comment]<>$new->data[Comment]) {
echo "ALTER TABLE `$table` COMMENT = '".$new->data[Comment]."';\n";
}
$tables[$tabnr]=$table;
$tabnr++;
}
}
foreach($tables as $table) {
$fields=array();
$old->Query("EXPLAIN $old_db.$table");
for ($i=0; $i<$old->rows;$i++) {
$old->Fetch($i);
$fields[$old->data[Field]]=1;
}
$new->Query("EXPLAIN $new_db.$table");
$oldfield=' FIRST';
for ($i=0; $i<$new->rows;$i++) {
$new->Fetch($i);
$field=$new->data[Field];
if ($fields[$field]) {
$data=$old->QueryRow("EXPLAIN SELECT `$field` FROM $old_db.`$table`");
echo "ALTER TABLE `$table` CHANGE `$field`$oldfield ;\n";
} else {
echo "ALTER TABLE `$table` ADD `$field`$oldfield ;\n";
}
$oldfield=" AFTER $field";
}
}
?>
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.