-1

I have a mySQL table that contains some fields that have the ',' char in them (strings). The thing is, when I'm trying to save the data that my php file generates into a CSV, it takes the ',' as a delimiter and displays the same field as two columns in Excel. This is the SQL code I use:

    "SELECT * INTO OUTFILE 'c:/mydata.csv' FROM my_table" 

now if the value of sum field in the SQL table is "a,b,c", each one of these letters will be in a different column instead of one .

How do I fix that?

thanks a lot!!

user3111518
  • 35
  • 1
  • 9
  • 2
    That shouldn't happen, as the value will be encapsulated in quotes. – Ryan Jan 02 '14 at 13:46
  • Use `ENCLOSED BY` clause in your SQL, here is example: http://stackoverflow.com/questions/356578/how-to-output-mysql-query-results-in-csv-format – Sean Doe Jan 02 '14 at 13:48
  • @user3111518 Try 1st comment in phpmyadmin export table/database into *.csv and view it in text editor. – Kyslik Jan 02 '14 at 13:49
  • The code given in your question will produce a tab-delimited file, in which commas have no special meaning (and therefore will not cause the problem that you cite). Please clarify exactly what you are doing, and what is going wrong. – eggyal Jan 02 '14 at 14:01

1 Answers1

2

Try this

SELECT * INTO OUTFILE 'c:/csvFile.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n' FROM my_table
Jenson M John
  • 5,499
  • 5
  • 30
  • 46