<?PHPDefine(' DATABASE1 ', ' coffeetest ');$DBI 1=NewDbmysql;$DBI 1->DBH = ' Mysql://root:[email protected]/'.DATABASE1;Define(' DATABASE2 ', ' sinatest ');$DBI 2=NewDbmysql;$DBI 2->DBH = ' Mysql://root:[email protected]/'.DATABASE2;//DB1$db 1=Array();$map=Array();$DBI 1->fetchmap ("SHOW TABLES",$map);$tables=Array_keys($map); for($i= 0;$i<Count($tables);$i++){ $map=Array(); $DBI 1->fetchmap ("DESCRIBE").$tables[$i],$map); $structures=Array(); foreach($map as $k=$v){ $structures[] = "$k=$v"; } $db 1[$tables[$i]] =$structures;}//DB2$db 2=Array();$map=Array();$DBI 2->fetchmap ("SHOW TABLES",$map);$tables=Array_keys($map); for($i= 0;$i<Count($tables);$i++){ $map=Array(); $DBI 2->fetchmap ("DESCRIBE").$tables[$i],$map); $structures=Array(); foreach($map as $k=$v){ $structures[] = "$k=$v"; } $db 2[$tables[$i]] =$structures;}//DB1 Compare DB2Echo("***** ". DATABASE1. "*****\n");foreach($db 2 as $table=$structures 2){ $structures 1=$db 1[$table]; if(Empty($structures 1)) { Echo(".$tableNot exist\n "); Continue; } for($i= 0;$i<Count($structures 2);$i++){ if(1==1 &&!)In_array($structures 2[$i],$structures 1)) Echo $table.".".$structures 2[$i]." \ n "; }}//DB2 Compare DB1Echo("***** ". DATABASE2. "*****\n");foreach($db 1 as $table=$structures 1){ $structures 2=$db 2[$table]; if(Empty($structures 2)) { Echo(DATABASE2. ").$tableNot exist\n "); Continue; } for($i= 0;$i<Count($structures 1);$i++){ if(1==0 &&!)In_array($structures 1[$i],$structures 2)) Echo $table.".".$structures 1[$i]." \ n "; }}?>
Using PHP script to assist MySQL database management 4-Two library table structure difference comparison