faqts : Computers : Databases : MySQL

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

18 of 60 people (30%) answered Yes
Recently 4 of 10 people (40%) answered Yes

Entry

How to programmatically (PHP) import a delimited text file into a MySQL database?

Feb 22nd, 2008 03:32
dman, Chad Currie, Hank Castello, http://sturly.com


There are a number of ways to import a delimited text file into a 
mysql database.
If you upload your comma (or otherwise) delimited file to your server, 
you can use something similar to the following to import the data.
LOAD DATA LOCAL INFILE '/importfile.csv' 
INTO TABLE test_table 
FIELDS TERMINATED BY ',' 
LINES TERMINATED BY '\n' 
(field1, filed2, field3); 
Another option is to use php to open your file, split each line of 
your file into an array, then loop through the array and use INSERT to 
import the contents of your file into a mysql table.