I am taking my data and writing a pipe delimited file --- for mysql import / sql import

What do I use to enclose my fields? Terminated should be: | --- am asking this as I look at my mysql paenl in phpmyadmin --- the reason I'm not just adding into mysql, but it will be moved eventually to sql and I want to have a pipe delimited file to handle the import --- although, I guess I could insert the records directly to mysql and export it later...

Fields terminated by
Fields enclosed by

    I would recommend using a CSV (comma-separated values) format, using the [man]fputcsv/man function to do most of the work for you. This is the most generally used format for delimited text files, and will easily transport to MySQL, Excel, etc.

      still am going to have to handle the quote marks and commas and some native html in the file ---- ok -- am working on it -- my php got rusty over the past few years

        You should be able to not enclose the fields in anything and just use the pipes to separate the columns. If you have to enclose it in something, use single quotes, then strip them out on import with:

        $column_data = trim( $column_data, '\'' );
        

        When you create the file, also make sure your actual data doesn't include any pipes. You can escape them (replace any pipe with a backslash then a pipe), or replace them with some kind of placeholder, like:

        $column_data = str_replace( '|', '[PIPE]', $column_data); //do the opposite when displaying
        

          The CSV specification deals just fine with internal quotes and commas, and the fputcsv() function understands that specification and implements it. phpMyAdmin also understands it (probably by using the PHP [man]fgetcsv/man function), so it's really quite a simple solution, assuming you are using PHP 5 (otherwise fputcsv() is not available, and you would therefore need to write/locate a replacement function).

            Write a Reply...