Author Topic: Import data to DB from CSV file - best practice?  (Read 644 times)

0 Members and 1 Guest are viewing this topic.

Offline kathasTopic starter

  • Enthusiast
    • View Profile
    • Greek Job Search Engine
Import data to DB from CSV file - best practice?
« on: September 01, 2007, 08:58:13 PM »
Hi to all,

I have an issue...
I will have a CSV file with the latest DB updates. I need to find the best practice for synchronizing my DB with the CSV using the least (execution time) queries possible.

The current script, for each user in the CSV:
Checks if he exists in the DB. If he exists it updates him, else it creates him.
That means it executes two queries for each user in the CSV.

I wonder how else can it be done...

Btw the script runs ok and has an execution time of 21.1.... seconds for importing 1000 users in the DB.

Regards,
Kathas
Greek Job Search Engine - Seriously Greek

Offline roopurt18

  • PHPFreaks Recommended
  • Fanatic
  • *
  • Gender: Male
  • le sigh
    • View Profile
    • rbredlau
Re: Import data to DB from CSV file - best practice?
« Reply #1 on: September 02, 2007, 12:33:22 AM »
Have a look here:
http://dev.mysql.com/doc/refman/5.0/en/load-data.html

I recommend using that to read into a temp table and then using:
INSERT ... SELECT
from the temp table into your final tables.

Offline kathasTopic starter

  • Enthusiast
    • View Profile
    • Greek Job Search Engine
Re: Import data to DB from CSV file - best practice?
« Reply #2 on: September 02, 2007, 07:17:43 AM »
Wow thanks a ton roopurt!!!

This must be a lot faster... i had no idea...

I will implement it and post here again for the time difference

---
Kathas
Greek Job Search Engine - Seriously Greek

PHP Freaks Forums

« on: »

Tired of these ads? Purchase a supporter subscription to get rid of them.