PHP synchronizes data from a table in MySQL two database

Source: Internet
Author: User

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

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.