简体   繁体   English

PHP Mysql:如何将特定的记录从一个数据库插入另一个数据库的另一台服务器?

[英]PHP Mysql : How to insert specific records from one db to another db different server?

db 1 Table 1 db 1表1

  1. Name 名称
  2. Dob 多布
  3. Address 地址
  4. ID ID
  5. Last Updated date 最后更新日期

Specific Records(using where condition) from the above table has to be inserted or updated to another db 2 table 2 of different server. 必须将上表中的特定记录(使用where条件)插入或更新到其他服务器的另一个db 2表2中。

If its only for one time, just do it in any database editing tool like MySQL Workbench or SQLyog. 如果只有一次,则可以在任何数据库编辑工具(如MySQL Workbench或SQLyog)中进行。

If you need to do it frequently, do it like this: 如果您需要经常这样做,请按照以下步骤操作:

  1. get a connection with db 1 与数据库1建立连接
  2. fetch all the records needed from db1 table1 and put them in an array 从db1 table1中获取所有需要的记录,并将它们放入数组中
  3. close the connection with db 1 and open a connection with db 2 关闭与数据库1的连接并打开与数据库2的连接
  4. loop through the array with records and insert/update them in db2 遍历带有记录的数组,然后在db2中插入/更新它们
  5. close the connection with db2. 关闭与db2的连接。

it shouldn't be that hard 不应该那么难

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM