0

I am trying to import some data in one table from a database to another database.
I cannot just copy them, because format of both tables of the two databases are different.

With the fetched data from one database, I am able to create insert queries.

I want to know which is better:

  1. Execute those queries in PHP itself by creating a new connection to second database.
  2. Write all queries to .sql file and then import it directly in second database.

I am looking at the aspects of performance and ease of implementation.

Note: I am expecting the data in the table to be more than ten thousand rows

2
  • We cannot say anything about ease of performance, since we cannot guess what modifications you have to make prior to reloading the data. Also we do not know what utilities you have available. So most likely the answer is: whatever approach appears easier to handle to you personally. Commented Mar 1, 2014 at 9:52
  • no, there is no modfication at all, only the name of the fields in the two tables will be different . Commented Mar 1, 2014 at 9:53

3 Answers 3

1

If you go with the first Option, There are chances that you could make some mistakes. I prefer you to go with the Second option to Write all queries to .sql file and then import it directly in second database. Thanks

vJ

Sign up to request clarification or add additional context in comments.

1 Comment

I guess, this will also save overhead of another PDO connection to the second database .
1

I would certainly go for the second option. Why use php for a one time action. You can just solve this in the database with SQL only

Comments

0

I would go for the second option. Then I would:

  • get an overview over both table structures
  • Export the data from the first table in a flat file format like CSV.
  • If necessary, transform the data from the first table to the second using a script or a tool.
  • Import the modified data into the second table.

The database vendors have good tools for exporting, manipulating and importing data.

If only the name of the tables are different, vendor tools importing feature often have good functionality for mapping data from one table to another. In my own case, I've used Oracle SQL developer, but please let me know your vendor and I can give you a pointer in the right direction.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.