Page 1 of 1

import text file into mysql

Posted: Wed May 24, 2006 3:21 pm
by dru_nasty
I have a table in mysql with two columns: id , email.
I'm trying to import a text file (textedit on mac) with a list of email addresses using the import text file feature in phpmyadmin.
Nothing is working. I've tried many different combinations with ; , separation and stuff but no luck.
Can someone show me a basic text file with a few emails that will import to my table?
The id column is auto_increment.

Thanks :D

Posted: Wed May 24, 2006 3:31 pm
by Burrito
you could use file() to create an array the loop over the array and do your inserts.

Posted: Wed May 24, 2006 3:36 pm
by dru_nasty
that looks promising. But with my infant php knowledge it would take me quite a while to get my head around that.
Isn't there just a way to setup the text file?

like:

email1;
email2;
emails3;

Posted: Wed May 24, 2006 3:37 pm
by Burrito
is each new line a separate email address?

Posted: Wed May 24, 2006 4:37 pm
by xpgeek
LOAD DATA INFILE

Code: Select all

mysql_query("LOAD DATA INFILE 'data.txt' INTO TABLE db2.my_table");

Posted: Wed May 24, 2006 4:43 pm
by dru_nasty
Burrito wrote:is each new line a separate email address?
yes it is.

Posted: Wed May 24, 2006 4:47 pm
by Burrito
xpgeek wrote:

Code: Select all

mysql_query("LOAD DATA INFILE 'data.txt' INTO TABLE db2.my_table");
wow! very nice, didn't know that existed. I'll have to give it a play in a bit.