mysql數(shù)據(jù)庫差異比較的PHP代碼
更新時間:2012年02月05日 20:48:18 作者:
這天遇見個需求:由于升級系統(tǒng) 這些系統(tǒng)從A庫升級到B庫,但是不知道數(shù)據(jù)庫添加了哪些字段和增加了哪些表
當(dāng)然可以去PHPMYADMIN里瀏覽一下。但是終究有遺漏吧。所以自己寫了個,比較數(shù)據(jù)庫差異的腳本(PHP的),方便一下自己。當(dāng)然代碼很簡單,就不講解了,貼代碼:
<?
mysql_connect('localhost','root','root');
mysql_select_db('tablea'); //標(biāo)準(zhǔn)的數(shù)據(jù)庫
$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][] =$s1[0];
}
}
mysql_close();
mysql_connect('localhost','root','root');
mysql_select_db('tableb');//需要比較的數(shù)據(jù)庫
$q2 = mysql_query("show tables");
while($s2 = mysql_fetch_array($q2)){
$name2= $s2[0];
$q3 = mysql_query("desc $name2");
while ($s3 = mysql_fetch_array($q3)) {
$aa[$name2][] =$s3[0];
}
}
mysql_close();
$f = $e = array();
$str = $fuhao ='';
foreach($a as $k=>$v){
if(!is_array($aa[$k])){
$e[] = $k;
}
else{
if(count($aa[$k]) <> count($v)){
foreach($v as $k1=>$v1){
if(!in_array($v1,$aa[$k])){
$f[$k][] = $v1;
}
}
}
}
}
echo "<pre>";
print_r($e);//缺少表
print_r($f);//缺少表的字段
?>
復(fù)制代碼 代碼如下:
<?
mysql_connect('localhost','root','root');
mysql_select_db('tablea'); //標(biāo)準(zhǔn)的數(shù)據(jù)庫
$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][] =$s1[0];
}
}
mysql_close();
mysql_connect('localhost','root','root');
mysql_select_db('tableb');//需要比較的數(shù)據(jù)庫
$q2 = mysql_query("show tables");
while($s2 = mysql_fetch_array($q2)){
$name2= $s2[0];
$q3 = mysql_query("desc $name2");
while ($s3 = mysql_fetch_array($q3)) {
$aa[$name2][] =$s3[0];
}
}
mysql_close();
$f = $e = array();
$str = $fuhao ='';
foreach($a as $k=>$v){
if(!is_array($aa[$k])){
$e[] = $k;
}
else{
if(count($aa[$k]) <> count($v)){
foreach($v as $k1=>$v1){
if(!in_array($v1,$aa[$k])){
$f[$k][] = $v1;
}
}
}
}
}
echo "<pre>";
print_r($e);//缺少表
print_r($f);//缺少表的字段
?>
相關(guān)文章
php+jQuery+Ajax實(shí)現(xiàn)點(diǎn)贊效果的方法(附源碼下載)
這篇文章主要介紹了php+jQuery+Ajax實(shí)現(xiàn)點(diǎn)贊效果的方法,結(jié)合實(shí)例形式詳細(xì)介紹了php結(jié)合jQuery的ajax無刷新提交實(shí)現(xiàn)點(diǎn)贊功能的具體步驟與相關(guān)技巧,需要的朋友可以參考下2015-12-12php 多進(jìn)程編程父進(jìn)程的阻塞與非阻塞實(shí)例分析
這篇文章主要介紹了php 多進(jìn)程編程父進(jìn)程的阻塞與非阻塞,結(jié)合實(shí)例形式分析了php 多進(jìn)程編程中父進(jìn)程的阻塞、等待、子進(jìn)程退出、非阻塞等相關(guān)操作技巧,需要的朋友可以參考下2020-02-02利用phpexcel對數(shù)據(jù)庫數(shù)據(jù)的導(dǎo)入excel(excel篩選)、導(dǎo)出excel
本篇文章主要介紹了利用phpexcel對數(shù)據(jù)庫數(shù)據(jù)的導(dǎo)入excel(excel篩選)、導(dǎo)出excel的相關(guān)知識。具有很好的參考價值。下面跟著小編一起來看下吧2017-04-04