About the SQL export CSV file comma delimiter problem

Source: Internet
Author: User
CSV file is generally "," as a delimiter, but now there is a lot of content in the database contains commas, how should this situation be handled?


Reply to discussion (solution)

Also ask this statement error, $rs [' Group_concat (' Concat_ws (' x ', ' sku ', ' quantity-purchased ') ' problem, should be the ' X ' question, how to deal with

echo $rs [' Ship-postal-code ']. ",". $address. ",". $rs [' Recipient-name ']. ",". $rs [' ship-city ']. ",". $rs [' ship-state ']. " , ". $rs [' Buyer-phone-number '].", ". $rs [' Group_concat (Concat_ws (' X ', ' sku ', ' quantity-purchased ')) '." \ r \ n ";

CSV file is generally "," as a delimiter, but now there is a lot of content in the database contains commas, how should this situation be handled? According to the format of the CSV file, when the content contains a comma is the content should be enclosed in double quotation marks, when the content contains double quotation marks, the double quotation marks should be converted into two double quotes, of course, the entire content is enclosed in double quotation marks
In general, the contents of the character type should be enclosed in double quotation marks
Also, the fgetcsv after php5.3 cannot be a recognition of Chinese in double quotes

Also ask this statement error, $rs [' Group_concat (' Concat_ws (' x ', ' sku ', ' quantity-purchased ') ' problem, should be the ' X ' question, how to deal with

PHP Code

echo $rs [' Ship-postal-code ']. ",". $address. ",". $rs [' Recipient-name ']. ",". $rs [' s ...]
$rs [' Group_concat (Concat_ws (' X ', ' sku ', ' quantity-purchased ') ')
Single quotes with single quotes, no mistakes.

Xuzuning Big,

One. Does this problematic statement add an escape character or double quotation marks?

Two. This statement is to write the contents of the database into a CSV file, what should I do??

Three. I Marson from the TXT file, ask the CSV file and TXT file which is not easy to break the problem caused by the delimiter??

The standard CSV is like this
"ABCD", "a" "", 123
The values for the three columns are ABCD, a ", 123, respectively.

Double quotation marks are usually omitted when there is no ambiguity
Aaa,bb,cccc

But if there is a Chinese
AAA, Kanji, 123
So php5.3 can only read 1, 3 columns of content, the 2nd column is empty

You just have to notice the fact that it doesn't matter what tool you use.
Since the tool has become a tool, it naturally has its merits.

$rs [' Group_concat (Concat_ws (' X ', ' sku ', ' quantity-purchased ') ')

How should this statement be changed?? I can't even read the data.

$rs ["Group_concat (Concat_ws (' X ', ' sku ', ' quantity-purchased ')"]

When exporting a file, you can select "Column delimiter (C)" At the bottom, and you can choose tab-delimited, but you will need to note that the delimiter is invalid when the "," symbol appears in the document.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.