PHP code for comparison of mysql database differences
Source: Internet
Author: User
Of course, you can browse in PHPMYADMIN. But there are omissions after all. So I wrote a script for comparing database differences (for PHP. Of course, the code is very simple and I will not explain it. paste the Code: Copy codeThe 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'); // the database 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 "<pre> ";
Print_r ($ e); // The table is missing
Print_r ($ f); // The table field is missing
?>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service