赞
踩
```php public function DBCompare() { //原数据库 连接 //Db::connect('mysql://root:1234@127.0.0.1:3306/thinkphp#utf8') $Db1 = Db::connect(''); //被检查数据库 连接 $Db2 = Db::connect(''); //数据库名称 $dataBaseName1 = ''; $ret1 = $Db1->query("SELECT TABLE_NAME, ENGINE FROM information_schema.TABLES WHERE TABLE_SCHEMA = ?",[$dataBaseName1]); //被检查数据库名称 $dataBaseName2 = ''; $ret2 = $Db2->query("SELECT TABLE_NAME, ENGINE FROM information_schema.TABLES WHERE TABLE_SCHEMA = ?",[$dataBaseName2]); $dataTable1 = []; $dataTable2 = []; for ($i = 0; $i < count($ret1); $i++) { $dataTable1[$i] = $ret1[$i]['TABLE_NAME']; } for ($i = 0; $i < count($ret2); $i++) { $dataTable2[$i] = $ret2[$i]['TABLE_NAME']; } $ret = array_diff($dataTable1, $dataTable2); if (count($ret) != 0){ var_dump("两个数据库之间的表差异,请先处理表"); dump($ret); return; } for ($i = 0; $i < count($dataTable1); $i++){ $result1 = $Db1->query("SHOW COLUMNS FROM ".$dataTable1[$i]); $result2 = $Db2->query("SHOW COLUMNS FROM ".$dataTable1[$i]); $dataTable1diff = []; $dataTable2diff = []; for ($j = 0; $j < count($result1); $j++) { $dataTable1diff[$j] = $result1[$j]['Field']; } for ($j = 0; $j < count($result2); $j++) { $dataTable2diff[$j] = $result2[$j]['Field']; } $ret = array_diff($dataTable1diff, $dataTable2diff); if (count($ret) != 0){ dump("两个数据库".$dataTable1[$i].",请处理"); dump($ret); } } dump("如果上面没有信息就表示两个数据库相同没有差异"); }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。