2 Replies - 804 Views - Last Post: 02 August 2009 - 12:11 PM Rate Topic: -----

#1 douffle   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 29-March 08

Transferring data from 1 database to another.

Posted 02 August 2009 - 10:30 AM

Hi

Iím new to PHP and MySQL but I have been dabbling around with it.
I am trying to write a small script to take specific data from one MySQL database and INSERT it into another. I have figured out how to retrieve the data from the fields I want in the first database and how to INSERT the data into the second database.

My problem is this:

Both databases use a field called category_id. The various categories are identified by a number as opposed to a name. The problem is that the number used to identify a specific category in the one database is not the same number being used in the second database to identify the same category.

There could be as many as 200 categories and I just canít come up with a reasonable idea. Having the code go through two separate lists of numbers comparing them doesn't sound very efficient.

Can anyone suggest to me a rough idea as to how best to deal with this problem?

Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: Transferring data from 1 database to another.

#2 BetaWar   User is offline

  • #include "soul.h"
  • member icon

Reputation: 1513
  • View blog
  • Posts: 8,295
  • Joined: 07-September 06

Re: Transferring data from 1 database to another.

Posted 02 August 2009 - 10:54 AM

Quote

Having the code go through two separate lists of numbers comparing them doesn't sound very efficient.

THat is the most common way of doing this.

However, if you wanted to do you could just keep the numbers the same and look at the first database for the correct categories. That would however require makign the selection from one database, then disconnecting and connecting to the other database.

Now, if you are using only one database with multiple tables you could do the same thing without having to worry about disconnecting.
Was This Post Helpful? 0
  • +
  • -

#3 douffle   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 29-March 08

Re: Transferring data from 1 database to another.

Posted 02 August 2009 - 12:11 PM

What I am trying to accomplish is this:

I have a site running a link directory which has been doing fairly well. It has just over 5000 links submitted. The script that the site uses is good but it lacks a couple of important features. I now have another script which is also good and it does have these features. I am trying to come up with a script that will import all of the links from the first script's database into the second script's database. I don't want to re-enter 5000 links by hand. :)

I have no problem retrieving the data from the first database but given the category ID numbers are different, I can't figure out how to insert them into the correct category in the second database. For example, the category_ID for the category "Automobiles" in the first database is 59 however, the category_ID for "Automobiles" in the second database is 234. There are 200 categories and their numbers all differ. Sounds confusing but I hope you get the idea.

Thanks.


View PostBetaWar, on 2 Aug, 2009 - 09:54 AM, said:

Quote

Having the code go through two separate lists of numbers comparing them doesn't sound very efficient.

THat is the most common way of doing this.

However, if you wanted to do you could just keep the numbers the same and look at the first database for the correct categories. That would however require makign the selection from one database, then disconnecting and connecting to the other database.

Now, if you are using only one database with multiple tables you could do the same thing without having to worry about disconnecting.

This post has been edited by douffle: 02 August 2009 - 12:16 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1