Forum Moderators: coopster

Message Too Old, No Replies

PHP and MySQL help

Trasnfer data between databases

         

stathis

12:12 pm on Nov 15, 2003 (gmt 0)

10+ Year Member



Hi all. I need your help on an issue i've come up against. As i am not very much into programming i need some help.

I have 2 databases. Let's say DB1 and DB2.

I need a query to transfer data between table A in DB1 and table A in DB2.

Can it be done?

Birdman

12:26 pm on Nov 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you have phpmyAdmin, you can simply 'export' the table and then go into the second db and 'import' the table. The new table should NOT exist in the second table prior to importing. It will be created at that time.

bluedevil

12:27 pm on Nov 15, 2003 (gmt 0)

10+ Year Member



Try this

INSERT INTO `db2`.`tableA` SELECT * FROM `db1`.`tableB`

jatar_k

6:16 pm on Nov 15, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



There are 2 possible scenarios here.

1. both db's are on the same box

bluedevil's query may be just fine but if you want to be more explicit

  • select your data from db1
  • save it into a variable or array
  • use mysql_select_db [ca.php.net] function to switch to db2
  • insert the data from the variable or array

    2. the db's are on different boxes

  • select your data from db1
  • save it into a variable or array
  • use mysql_connect [ca.php.net] function to connect to server with db2
  • insert the data from the variable or array
  •