views:

2355

answers:

5

I am trying to import a .csv file into a MySQL table via phpMyAdmin.

The .csv file is separated by pipes, formated like this:

data|d'ata|d'a"ta|dat"a|
data|"da"ta|data|da't'a|
dat'a|data|da"ta"|da'ta|

The data contains quotes. I have no control over the format in which I recieve the data -- it is generated by a third party.

The problem comes when there is a | followed by a double quote. I always get an "invalid field count in CSV input on line N" error.

I am uploading the file from the import page, using Latin1, CSV, terminated by |, separated by ".

I would like to just change the "enclosed by" character, but I keep getting "Invalid parameter for CSV import: Fields enclosed by". I have tried various characters with no success.

How can I tell MySQL to accept this format in phpMyAdmin?

Setting up these tables is the first step in writing a program that will use uploaded gzipped .csv files to maintain the catalog of an e-commerce site.

A: 

you could modify the csv files by adding a \ in front of every ' right?

Maurice Kroon
I can't modify the incoming files
Andrew Swift
you mention that you will use uploaded gzipped csv files right? i assume this is an automated process right? you can unpack it, fix it, and import it right? (however, might be a bit overdoing it but it works i guess)
Maurice Kroon
A: 

Have you tried blanking the boxes that read "Fields enclosed by" and "Fields escaped by"? I have not used phpMyAdmin, but Google suggests others have had success with this method.

Conspicuous Compiler
I tried that and got g "Invalid parameter for CSV import: Fields enclosed by".
Andrew Swift
A: 

You might consider just writing your own LOAD DATA INFILE query, seems like you'll need one anyway since this process will be part of an application at some point.

Zenshai
It's true, but I am still working out the table structure with the provider. I'd like to avoid writing code as long as the table structures aren't finalized. Using phpMyAdmin to import gives me a quick way to see that my table structure matches the files I receive.
Andrew Swift
A: 

I found a hack that works -- I use the $ as the "enclosed by" character and all is well. Since this is for a European site, I know that they'll never use it in the table content.

Andrew Swift
A: 

Dear,

you can use http://dbTube.org. It is a native excel importer for the PHP, mySQL enviroment.

Tim Burton
Thanks, I'll keep it in mind for the next time.
Andrew Swift