Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script to import CSV into MySQL 1

Status
Not open for further replies.

Tels

IS-IT--Management
Jul 10, 2001
290
GB
Hi. I want to export data from GoldMine into MySQL.

I have done this successfully with a long LOAD command, but I'd like a PHP script to do this for me (as the LOAD command is a little lacking).

The CSV data is in the format "field1","field2","field3"
and each record is terminated by a carriage return (\n)

As each GM export will contain the same records again and again I'd like the script to delete the old records in the SQL database before adding the updated records. in effect, overwriting the old data.

I really don't have a clue where to start, I feel I will probably have to modify whatever scripts I can find closest to what I need....

Any ideas / premade scripts / websites to help are most appreciated. Thankyou.

Tels
Mixed Linux/Win2000 Network Administrator
 
If your data import requirements are large, I recommend you use the MySQL LOAD command -- it's a lot faster than doing it a line at a time from a script.

I had to do something similar with a large import dataset (>100,000 records/week). I found that the best solution, in terms of script run time, was to write a script which took in the CSV, massaged the data and rewrote it to a new file, then instructed MySQL to import it using the LOAD command. I used perl DBI rather than PHP, but only because I run PHP as an Apache module on the server and my interface was not HTTP.

Changing from a "line-by-line" import to a "massage and LOAD" import cut my run time from more than 2 minutes to less than 30 seconds. ______________________________________________________________________
TANSTAAFL!
 
I'll keep that in mind... What is the syntax I would need to use for the LOAD command?
Mixed Linux/Win2000 Network Administrator
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top