import text file into mysql

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dru_nasty
Forum Commoner
Posts: 81
Joined: Sat Sep 10, 2005 10:26 am

import text file into mysql

Post 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
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

you could use file() to create an array the loop over the array and do your inserts.
dru_nasty
Forum Commoner
Posts: 81
Joined: Sat Sep 10, 2005 10:26 am

Post 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;
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

is each new line a separate email address?
User avatar
xpgeek
Forum Contributor
Posts: 146
Joined: Mon May 22, 2006 1:45 am
Location: Kyiv, Ukraine
Contact:

Post by xpgeek »

LOAD DATA INFILE

Code: Select all

mysql_query("LOAD DATA INFILE 'data.txt' INTO TABLE db2.my_table");
dru_nasty
Forum Commoner
Posts: 81
Joined: Sat Sep 10, 2005 10:26 am

Post by dru_nasty »

Burrito wrote:is each new line a separate email address?
yes it is.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post 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.
Post Reply