zoukankan      html  css  js  c++  java
  • php同步mysql两个数据库中表的数据

    分别创建两个数据库和两张表
    study库-zone表
    teaching库-area表

    //****SQL脚本****//

    1.创建teaching数据库area数据表
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    create database teaching;
     
    CREATE TABLE  `area` (
     
     `id` int(11) NOT NULL AUTO_INCREMENT,
     
      `areaID` varchar(50) CHARACTER SET utf8 DEFAULT NULL,
     
     `area` varchar(60) CHARACTER SET utf8 DEFAULT NULL,
     
      `father` varchar(6) CHARACTER SET utf8 DEFAULT NULL,
     
     PRIMARY KEY (`id`)) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=3187 ;

      

    2.给area表中添加数据

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    INSERT INTO `area` (`id`, `areaID`, `area`, `father`) VALUES
     
    (2759, '610101''市辖区''610100'),(2760, '610102''新城区''610100'),
     
    (2761, '610103''碑林区''610100'),(2762, '610104''莲湖区''610100'),
     
    (2763, '610111''灞桥区''610100'),(2764, '610112''未央区''610100'),
     
    (2765, '610113''雁塔区''610100'),(2766, '610114''阎良区''610100'),
     
    (2767, '610115''临潼区''610100'),(2768, '610116''长安区''610100'),
     
    (2769, '610122''蓝田县''610100');

      

    3.创建study数据库zone数据表

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    create database study;
     
    CREATE TABLE `zone` (
     
     `id` int(11) NOT NULL AUTO_INCREMENT,
     
    `areaID` varchar(50) CHARACTER SET utf8 DEFAULT NULL,
     
      `area` varchar(60) 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文件执行数据表同步

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    <?php
    $conn = mysqli_connect('localhost''root''''study');
     
    $delSql="dalete from `zone`";
    $rel_del = mysqli_query($conn,$delSql);
    $sql = "insert into study.zone(`id`,`areaID`,`area`,`father`) select `id`,`areaID`,`area`,`father` from teaching.area order by id asc";
    $result = mysqli_query($conn,$sql);
     
    if($result){
      echo "<font color='green'>恭喜恭喜,数据同步成功</font>";
    }else{
      echo "<font color='red'>对不起,数据同步出错,请检查!</font>";
    }
     
     
    ?>

      

    复制代码
  • 相关阅读:
    Ubuntu Linux Matlab 安装 中文乱码 桌面启动器 Could not find the main class: java/splash.png. 终端terminal 直接运行 matlab
    Ubuntu Linux 官网 u盘安装 u盘系统 图文教程
    从google map google earth获得大图 方法总结
    论文查重网址
    [ZZ] Computer Science Conference Rankings
    Ubuntu linux 信使 iptux Window 飞鸽 ipmsg 飞秋 feiq 文件传输
    Ubuntu Linux Matlab mex
    Ubuntu Dell OptiPlex 990 Intel Gigabit CT Desktop Adapter网卡驱动安装
    C++的File类文件操作
    GIS软件比较
  • 原文地址:https://www.cnblogs.com/apolloren/p/14003626.html
Copyright © 2011-2022 走看看