PHP code for mysql database difference comparison_PHP tutorial

WBOY
Release: 2016-07-21 15:20:50
Original
838 people have browsed it

Of course, you can browse it in PHPMYADMIN. But there must be some omissions after all. So I wrote a script (PHP) to compare database differences to facilitate myself. Of course the code is very simple, so I won’t explain it. Paste the code:

Copy the code The code is as follows:

mysql_connect('localhost','root','root');
mysql_select_db('tablea'); //Standard 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][] =$s1[0];
}
}
mysql_close();
mysql_connect('localhost','root','root ');
mysql_select_db('tableb');//Database that needs to be compared
$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 "
"; 
print_r($e);//The table is missing
print_r($f);//The fields of the table are missing
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/325038.htmlTechArticleOf course you can browse it in PHPMYADMIN. But there must be some omissions after all. So I wrote a script (PHP) to compare database differences to facilitate myself. Of course the code is very simple...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!