Using PHP script to assist MySQL database management 4-Two library table structure difference comparison

Source: Internet
Author: User
Tags db2 php script

<?PHPDefine(' DATABASE1 ', ' coffeetest ');$DBI 1=NewDbmysql;$DBI 1-&GT;DBH = ' Mysql://root:[email protected]/'.DATABASE1;Define(' DATABASE2 ', ' sinatest ');$DBI 2=NewDbmysql;$DBI 2-&GT;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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.