macromedia.dreamweaver.appdev
[Top] [All Lists]

Re: Replace coma in a csv file before importing into database?

Subject: Re: Replace coma in a csv file before importing into database?
From: Michael Fesser
Date: Sun, 07 Sep 2008 17:25:39 +0200
Newsgroups: macromedia.dreamweaver.appdev

.oO(taywanqi)

>Hi all, I have a csv file that i need to import into my sql database. The csv 
>file itself contains extra commas, that is screwing the whole app up since 
>mysql reads the comma as a field separator. I have tried using a different 
>field separator and also other methods such as implode/explode/str_replace 
>etc, 
>but it doesnt seem to work. Can anybody help me? Thanks!!

Looks like the CSV-file is not properly formatted. If some fields also
contain commas, they have to be quoted, e.g.

foo,bar,"23,42"

These are just three fields, not four. And IMHO MySQL will handle this
correctly. Also have a look at the various options for a LOAD DATA
statement. If it still doesn't work, please post a short excerpt from
the CSV and the query you're using for the import.

Micha

<Prev in Thread] Current Thread [Next in Thread>