简体   繁体   中英

How can I move a specific set of user data from one MySQL database to another with PHP?

I have two MySQL databases with similar sets of data, both on the same server. I need to grab select fields from a given table in database X and move them into given fields of a table in database Y. The table names are different, but field names are the same except for a prefix on database Y.

The database should be moved based on a unique username that exists on both ends. So I would get the data for username A, then find username A in database Y, and copy the data from the select fields for that user.

Any direction or advice would be much appreciated. This by the way would be a process to run as needed, not something that needs to continuously run. Using PHP 5.3 and MySQL 5.

INSERT INTO database1.customer (
  id
  fname,
  etc
) 
SELECT 
  id
  fname,
  etc
FROM
  database2.customer 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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