利用PHP脚本辅助MySQL数据库管理4-两个库表结构差异比较
2024-08-29 18:28:30
<?php
define('DATABASE1', 'coffeetest');
$dbi1 = new DbMysql;
$dbi1->dbh = 'mysql://root:mysql@127.0.0.1/'.DATABASE1; define('DATABASE2', 'sinatest');
$dbi2 = new DbMysql;
$dbi2->dbh = 'mysql://root:mysql@127.0.0.1/'.DATABASE2; // db1
$db1 = array();
$map = array();
$dbi1->fetchMap("SHOW TABLES", $map);
$tables = array_keys($map);
for($i=0; $i<count($tables); $i++){
$map = array();
$dbi1->fetchMap("DESCRIBE ".$tables[$i], $map);
$structures = array();
foreach($map as $k=>$v){
$structures[] = "$k=$v";
}
$db1[$tables[$i]] = $structures;
} // db2
$db2 = array();
$map = array();
$dbi2->fetchMap("SHOW TABLES", $map);
$tables = array_keys($map);
for($i=0; $i<count($tables); $i++){
$map = array();
$dbi2->fetchMap("DESCRIBE ".$tables[$i], $map);
$structures = array();
foreach($map as $k=>$v){
$structures[] = "$k=$v";
}
$db2[$tables[$i]] = $structures;
} // db1 compare db2
echo("***** ".DATABASE1." *****\n");
foreach($db2 as $table=>$structures2){
$structures1 = $db1[$table];
if(empty($structures1)) {
echo(".$table not exist\n");
continue;
}
for($i=0; $i<count($structures2); $i++){
if(1==1 && !in_array($structures2[$i], $structures1))
echo $table.".".$structures2[$i]."\n";
}
} // db2 compare db1
echo("***** ".DATABASE2." *****\n");
foreach($db1 as $table=>$structures1){
$structures2 = $db2[$table];
if(empty($structures2)) {
echo(DATABASE2.".$table not exist\n");
continue;
}
for($i=0; $i<count($structures1); $i++){
if(1==0 && !in_array($structures1[$i], $structures2))
echo $table.".".$structures1[$i]."\n";
}
}
?>
最新文章
- FastReport 中添加二维码功能.(Delphi)
- sass跨文件重写变量
- 深入理解JVM内存模型
- Linux comands
- 项目源码--Android新闻财经类商用要求源码
- FastJson的使用方法总结
- Realm数据库的简单介绍和使用
- ops-web运维平台data.jsp-jquery-mootools
- C++编程求数组中重复的数字
- (转)如何在Eclipse中查看JDK类库的源代码
- Python 面向对象高阶-----metaclass
- windows10安装JIRA
- 洛谷 P2802 回家
- thrift使用总结
- input文本框禁止修改文本&mdash;&mdash;disabled和readonly属性的作用及区别
- 【xsy1018】 小A的字母游戏 扩展CRT
- 【枚举&;数据结构】【P2484】 [SDOI2011]打地鼠
- HTML容易遗忘内容(二)
- 1095 Cars on Campus
- Spring中与Spring相关的注解
热门文章
- python 内置函数(二) 进阶函数 递归内容及二分法查找 知识点
- Pandas之数据结构
- SQL Server 2008 R2官方中文版下载
- Codeforces Beta Round #34 (Div. 2)
- 微信小程序开发——导航失效的解决办法
- TZOJ 4848 货车运输(最大生成树+倍增lca)
- f5 SSL及证书
- 【分布式架构】“spring cloud”与“dubbo”微服务的对比
- 利用jenkins+saltstack+sh 修改nginx配置文件并重新加载
- Beyound Compare中比较java字节码class文件