• 数据库比对脚本(PHP版)


    $config = [
        'hotfix' => [
            'host'=>'',
            'port'=>'',
            'account'=>'',
            'password'=>'',
            'database'=>'',
        ],
        'release' => [
            'host'=>'',
            'port'=>'',
            'account'=>'',
            'password'=>'',
            'database'=>'',
        ],
        'master' => [
            'host'=>'',
            'port'=>'',
            'account'=>'',
            'password'=>'',
            'database'=>'',
        ],
    ];
    
    function display($compare1,$compare2){
        $html = '<title>数据库对比脚本</title>';
        $html .= '<form method="GET">
                原数据库:
                <select name="db1">
                    <option value="hotfix"'.($compare1=='hotfix'?'selected="selected"':"").'>开发站</option>
                    <option value="release"'.($compare1=='release'?'selected="selected"':"").'>测试站</option>
                    <option value="master"'.($compare1=='master'?'selected="selected"':"").'>正式站</option>
                </select>
                现数据库:
                <select name="db2">
                    <option value="hotfix"'.($compare2=='hotfix'?'selected="selected"':"").'>开发站</option>
                    <option value="release"'.($compare2=='release'?'selected="selected"':"").'>测试站</option>
                    <option value="master"'.($compare2=='master'?'selected="selected"':"").'>正式站</option>
                </select>
                <input type="submit" value="对比" /><br><br>';    
        $html .= '相比原数据库,现数据库:<br>';
        return $html;
    }
    
    function databaseData($config,$compare){
        $aaaaa = mysql_connect(
            $config[$compare]['host'].':'.$config[$compare]['port'],
            $config[$compare]['account'],
            $config[$compare]['password']
        );
        mysql_select_db($config[$compare]['database']); //标准的数据库
        $q = mysql_query("show tables");
        while($s = mysql_fetch_array($q)){
            $name = $s[0];
            $q1 = mysql_query("desc $name");
            while ($s1 = mysql_fetch_array($q1)) {
                $a[$name]['field'][] =$s1[0];
                $a[$name]['format'][] =$s1[1];
            }
        }
        mysql_close();
        return $a;
    }
    
    function dataCompare($a,$aa){
        $f = $e = array();
        $str = $fuhao ='';
        foreach($a as $k=>$v){
            if(!is_array($aa[$k])){
                $e[] = $k;
                echo "<div style='background:#fdd'>缺少表:<font color='blue'>$k</font></div>";
            }
            else{
                foreach($v['field'] as $k1=>$v1){
                    if(!in_array($v1,$aa[$k]['field'])){
                        $f[$k]['field'][] = $v1;
                        echo "<div style='background:#ff9'>表<font color='blue'>".$k."</font>缺少字段: <font color='red'>".$v1."</font>"."</div>";
                    }else{
                        if(!in_array($v['format'][$k1],$aa[$k]['format'])){
                            $f[$k]['format'][] = $v['format'][$k1];
                            echo "<div style='background:#ddd'>表<font color='blue'>".$k."</font>字段 <font color='red'>".$v1."</font>修改为<font color='green'>".$v['format'][$k1]."</font>"."</div>";
                        }
                    }
                }
            }
        }
    }
    
    $compareOne = isset($_GET['db1'])?$_GET['db1']:'';
    $compareTwo = isset($_GET['db2'])?$_GET['db2']:'';
    echo display($compareOne,$compareTwo);
    $a = databaseData($config,$compareOne);
    $aa = databaseData($config,$compareTwo);
    dataCompare($a,$aa);
  • 相关阅读:
    C语言-第四周作业
    第8次Scrum会议(10/20)【欢迎来怼】
    例行报告(20171011-20171019)
    C语言--第二周作业评分和总结(5班)
    C语言-第三周作业
    第一次Scrum会议(10/13)【欢迎来怼】
    单元测试之四则运算
    四则运算V1.1
    例行报告(20170927-20171010)
    C语言--第一周作业评分和总结(5班)
  • 原文地址:https://www.cnblogs.com/boystar/p/6101407.html
Copyright © 2020-2023  润新知