Uploading .csv or .txt files to populate an existing sql tbl

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
User avatar
edawson003
Forum Contributor
Posts: 133
Joined: Thu Aug 20, 2009 6:34 am
Location: Los Angeles, CA - USA

Uploading .csv or .txt files to populate an existing sql tbl

Post by edawson003 »

I would like to build functionality that would allow my admin users the ability to upload .csv or .txt files with a specified numbers of columns (and data types) and column titles to populate an existing mysql table. Does anyone know of a tutorial or something I can follow to set something like this up?
User avatar
Robert07
Forum Contributor
Posts: 113
Joined: Tue Jun 17, 2008 1:41 pm

Re: Uploading .csv or .txt files to populate an existing sql tbl

Post by Robert07 »

Hello,
I've written a post about this subject at http://www.goodfeelingplace.com/free-md ... onversion/, where I discussed how I took an access mdb file, exported it to a text file, then created a script (which you can download there) which would create sql statements that could be copied into phpmyadmin and run. For your application, you could take my script and modify it to actually run the sql against your database instead of printing it out.
Regards,
Robert
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Uploading .csv or .txt files to populate an existing sql tbl

Post by Eran »

You can import CSV and text files directly into mysql using LOAD DATA INFILE - http://dev.mysql.com/doc/refman/5.1/en/load-data.html
User avatar
edawson003
Forum Contributor
Posts: 133
Joined: Thu Aug 20, 2009 6:34 am
Location: Los Angeles, CA - USA

Re: Uploading .csv or .txt files to populate an existing sql tbl

Post by edawson003 »

Ok, cool. I will look into both options. Thank you much!
Post Reply