Preparing SQL insert statements from CSV files

Preparing SQL insert statements from CSV files

am 05.10.2007 04:01:29 von T K

Hi,

I have to parse csv files and put them into database. I was able to
parse the files by fgetcsv() and made an HTML table. But, when it
comes to parse more closely and make "INSERT INTO" statement, then I'm
having problems with, probably "for-loop".

For example, how do you do this task with the simple csv file shown at
https://admin.easymail.rmplc.co.uk/admin_help/csv.htm .

T

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Preparing SQL insert statements from CSV files

am 05.10.2007 04:30:13 von dmagick

T K wrote:
> Hi,
>
> I have to parse csv files and put them into database. I was able to
> parse the files by fgetcsv() and made an HTML table. But, when it
> comes to parse more closely and make "INSERT INTO" statement, then I'm
> having problems with, probably "for-loop".

Do you need to do anything to the data before it's inserted?

Check out http://dev.mysql.com/doc/refman/5.0/en/load-data.html if
you're using mysql - it can load a csv file directly (providing it's
properly formatted etc).

--
Postgresql & php tutorials
http://www.designmagick.com/

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Preparing SQL insert statements from CSV files

am 05.10.2007 04:33:52 von Bruce Cowin

And if you're using MS SQL Server, you can use BULK INSERT.


Regards,

Bruce

>>> Chris 5/10/2007 3:30:13 p.m. >>>
T K wrote:
> Hi,
>
> I have to parse csv files and put them into database. I was able to
> parse the files by fgetcsv() and made an HTML table. But, when it
> comes to parse more closely and make "INSERT INTO" statement, then
I'm
> having problems with, probably "for-loop".

Do you need to do anything to the data before it's inserted?

Check out http://dev.mysql.com/doc/refman/5.0/en/load-data.html if
you're using mysql - it can load a csv file directly (providing it's
properly formatted etc).

--
Postgresql & php tutorials
http://www.designmagick.com/

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php