Page 1 of 1

How to inser data to Mysql From CSV file

Posted: Thu Sep 27, 2007 4:45 am
by vinoth
Hi

I am working on PHP project..

The client sent the details in CSV file is there any possible way to insert the data into Mysql

Help me by providing some suggestions & guidelines to achieve this

Posted: Thu Sep 27, 2007 8:14 am
by feyd
Take a look at LOAD DATA FROM INFILE

Posted: Thu Sep 27, 2007 8:28 am
by kalfsnor
if you have access to PHPadmin you could use "import", no? set file format to CSV.

Posted: Thu Oct 04, 2007 5:55 am
by vinoth
hi..

Sorry for late reply..

If I use Load inline function it was inserted into an single table.
But I want to split the rows of the CSV file and insert into 4 different tables..

Posted: Thu Oct 04, 2007 7:55 am
by feyd
You will need to write some code to do that then.

Posted: Thu Oct 04, 2007 7:59 am
by VladSun
feyd wrote:You will need to write some code to do that then.
It could be done only with SQL queries, without PHP code (this is still "some code" :) ).

Posted: Thu Oct 04, 2007 8:09 am
by feyd
VladSun wrote:It could be done only with SQL queries, without PHP code (this is still "some code" :) ).
It would require multiple calls to LOAD DATA INFILE, not a single query. It may as well be code handling it at that point.

Posted: Thu Oct 04, 2007 8:28 am
by VladSun
feyd wrote:
VladSun wrote:It could be done only with SQL queries, without PHP code (this is still "some code" :) ).
It would require multiple calls to LOAD DATA INFILE, not a single query. It may as well be code handling it at that point.
Or one call to LOAD DATA INFILE, multiple calls to INSERT ... SELECT, and DROP the first table - that is what I meant. Just pure SQL :)