im just testing something on someone webspace, mailny exporting some data from mysql into a text/zip file for them to back up on their hard drive.

When there is a comma usually there is a backslash automatically inserted infront of it. (like so \')
But for some reason its inserting a second comma instead of a backslash. ('')

Is this how it should be? and if the data was ever uploded from this dump file, would it work as same was a a backslash infront of a comma?

any help appreciated!

    Yes. This is how comma-delimited files work. If you're using single quotes to identify a text string, then using two single quotes will escape a single quote in your string. Same goes for double quotes.

    Not all CSV importers are robust. If you're using phpmyadmin or a similar tool, you should be fine. If its mission critical to know, then test it out real quick on a test table before doing it to a live table.

      I will tell you my main concern.....

      I run a site which uses around 100gb per month of bandwidth. Most of this is just through pure traffic on a forum (which connects to mysql). I have been through many hosts which dont like this high usage. So I always like to keep a regular back up of my data (exported via the options in phpmyadmin), just incase I have to suddenly switch to a new host, in which case I hand over to the new host the zip file with data in for them to upload and insert.

      In all my previous hosts comma's automatically have a backslash inserted infront (which I understand).
      But the new host I have just moved to, when I export in the same way another comma is inserted infront of exisiting commas instead of a backslash.

      I have asked my host why this is but they dont understand what im talking about (which is why im asking the question in here).

      Im kinda new to mysql, and so dont really understand 'robust' and things.

      I just couldnt understand why there was a difference, ie what the difference was between the extra comma or the backslash.
      My new host is using a newer version of phpmyadmin, so I didnt know if it was down to that.
      Would using the double comma instead of backslash and comma would work across all versions of phpmysql?

      Sorry if the above isnt explained all that well.

      Thank you for your help AstroTeg 😃

        Maybe post 1 complete line of what you're referring to. That could help me out a bit.

        In the meantime, you'll want to dig up some specs on CSV files. They are really not too difficult. But you have to get into things like - how are you specifying text versus a number? A number is usually by itself. Text can be wrapped in quotes, double quotes, or nothing at all. Depending on how the text is wrapped, will depend on what needs to be escaped. If there's no quotes, then the comma needs be escaped. If its using single quotes, then the single quotes needs to be escaped. Etc.

          I have attatched an image to this post, containing 2 examples.

          Example 1: uses another comma to escape a comma.

          Example 2: uses a backslash to escape a comma (this is the way im used to seeing it).

          Both these examples are produced from a dump file exported via the export function in phpmyadmin.

          What I want to know, is: do both these examples work in exactly the same way if I ever needed to upload this data again to another database?

          Once again thanks!

            Ahh!!

            Ok. I thought you were working directly from a CSV file. But you're not. I see.

            The double single quote is Sybase syntax for escaping a single quote. THIS IS NOT CSV formatting. The second method is escaping the single quote as well.

            Check out MySQL's page on this:

            http://dev.mysql.com/doc/mysql/en/string-syntax.html

            You'll be fine IF AND ONLY IF your exported data will be pulled into another MySQL database. If you had to import it into a different database engine you'll find you'll have a lot of problems.

              yes...only on mysql.

              Thats the page my host pointed me towards, but that php manual is written with the presumption you have a lot of previous knowledge...I dont!

              Anyway, thanks for your help!!! I can now safely back up my data with the knowldge that it is readable if ever I need to use the backed up dump files!!
              cheers!! 😃

                Write a Reply...