Jamison Dance
Jamison Dance

Reputation: 20184

How do I do an SQL join with a CSV file in php (drupal specifically)?

Hey guys, here is my problem. I am writing a Drupal module. A user uploads a CSV list of e-mail addresses to a server in a form. I need to do a JOIN on my database to get a list of unique addresses from the CSV file and the DB (No, it is not for spam :).

How would I turn the uploaded CSV file into a format that I can do an SQL join on it with a table in my db in php?

Upvotes: 1

Views: 791

Answers (2)

yukondude
yukondude

Reputation: 24663

Loading the data into a "temporary" table makes it very easy to deal with. You will want to apply an index to the table to speed joins, but it may be faster to drop the index before loading the data, and then recreate it afterwards. (As with all performance advice, measure your own results before adopting a more complex solution.)

Upvotes: 1

Frank Farmer
Frank Farmer

Reputation: 39356

You can load it directly using LOAD DATA INFILE

Or, if you prefer, read it in PHP with fgetcsv(), munge to your heart's content, and them INSERT into a temporary table.

Upvotes: 2

Related Questions