Create two databases and two tables respectively
Study Library-zone Table
Teaching Library-area Table
SQL Script ****//
1. Create the Teaching Database area data table
Create database teaching; CREATE TABLE ' area ' ( ' id ' int (one) not NULL auto_increment, ' areaid ' varchar () CHARACTER SET UTF8 DEFAULT NU LL, ' area ' varchar (CHARACTER) set UTF8 default null, ' father ' varchar (6) CHARACTER set UTF8 default null, P Rimary KEY (' id ')) engine=myisam DEFAULT Charset=utf8 auto_increment=3187;
2. Add data to the area table
INSERT into ' area ' (' IDs ', ' areaid ', ' area ', ' father ') VALUES (2759, ' 610101 ', ' District ', ' 610100 '), (2760, ' 610102 ', ' New Town ', ' 610 100 '), (2761, ' 610103 ', ' Beilin District ', ' 610100 '), (2762, ' 610104 ', ' Lianhu District ', ' 610100 '), (2763, ' 610111 ', ' Baqiao District ', ' 610100 '), (2764, ' 610112 ', ' Weiyang District ', ' 610100 '), (2765, ' 610113 ', ' Yanta District ', ' 610100 '), (2766, ' 610114 ', ' Yanliang ', ' 610100 '), (2767, ' 610115 ', ' Lintong ', ' 61 0100 '), (2768, ' 610116 ', ' Changan District ', ' 610100 '), (2769, ' 610122 ', ' Lantian County ', ' 610100 ');
3. Create a study database zone data table
Create DATABASE study; CREATE TABLE ' zone ' ( ' id ' int (one) not null auto_increment, ' areaid ' varchar () CHARACTER SET UTF8 DEFAULT NULL, ' Area ' varchar CHARACTER set UTF8 default null, ' father ' varchar (6) CHARACTER set UTF8 default null, PRIMARY KEY ( ' id ') engine=myisam DEFAULT Charset=utf8 auto_increment=3187;
PHP file to perform data table synchronization
<?php $conn = mysqli_connect (' localhost ', ' root ', ' ', ' study '); $delSql = ' dalete from ' zone '; $rel _del = Mysqli_query ($ conn, $delSql); $sql = "INSERT into Study.zone (' IDs ', ' areaid ', ' area ', ' father ') select ' IDs ', ' areaid ', ' area ', ' father ' from Teaching.area ORDER by ID ASC "; $result = Mysqli_query ($conn, $sql), if ($result) {echo" <font color= ' green ' > Congratulations, Data synchronization Success </font> ";} else{echo "<font color= ' red ' > Sorry, data synchronization error, please check!</font>";}? >
PHP synchronizes data from a table in MySQL two database