Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9006431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:24:35+00:00 2026-06-16T01:24:35+00:00

I am working on a script that routinely uploads a CSV file into a

  • 0

I am working on a script that routinely uploads a CSV file into a MySQL database. The issue is that one of the fields in the CSV file contains user generated text, which may include quotations and other characters which are unfriendly to MySQL.

I have determined that the most efficient way to upload the CSV file is via MySQL’s ‘LOAD DATA INFILE’ command. Here is the command as it appears in MyPHPAdmin when I upload the CSV:

LOAD DATA LOCAL INFILE '/home/myfolder/tmp/property_re_1.csv' REPLACE INTO TABLE `markers`
    FIELDS TERMINATED BY ';' ENCLOSED BY '"' ESCAPED BY '\\'
    LINES TERMINATED BY '\r\n' # 2 rows affected.

Simply loading the CSV with this command does not work, as the process terminates as soon as it runs into a ‘”‘ and the “ESCAPED BY ‘\'” doesn’t appear to be serving its purpose.

In this case, I think I may have to escape the quotations in the CSV file programmatically with PHP first. Then load the “Escaped” file into MySQL with the LOAD DATA INFILE command in SQL.

I am sure this is a common problem that has a “best practice” solution. Essentially, my script needs to “clean up” a CSV file before loading it into a MYSQL table.

Here is a link to the actual SQL table and CSV file I am working with to help wiser minds wrap their heads around this one: https://www.dropbox.com/sh/4iq10i51qlqyq8q/UjEQwvXKDA

Thanks for your help in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T01:24:36+00:00Added an answer on June 16, 2026 at 1:24 am

    The data file on your dropbox has fields delimited by ,, optionally enclosed by ", lines delimited by \n and containing a header row; whereas your statement above is for a file with fields delimited by ;, always enclosed by ", lines delimited by \r\n and not containing any header row.

    That said, it’s also for a file named data.csv whereas the one on Dropbox is named property_re_1.csv.

    mysql> CREATE TABLE IF NOT EXISTS `markers` (
        ->   `L_ListingID` int(20) NOT NULL,
        ->   `L_Class` int(5) NOT NULL,
        ->   `L_Type_` int(10) NOT NULL,
        ->   `L_Status` varchar(10) NOT NULL,
        ->   `L_AskingPrice` float NOT NULL,
        ->   `L_Remarks` text NOT NULL,
        ->   `L_Address` varchar(50) NOT NULL,
        ->   `L_City` text NOT NULL,
        ->   `L_State` varchar(10) NOT NULL,
        ->   `LO1_OrganizationName` varchar(65) NOT NULL,
        ->   `LA1_AgentLicenseID` int(20) NOT NULL,
        ->   `LA1_UserFirstName` varchar(50) NOT NULL,
        ->   `LA1_UserLastName` varchar(50) NOT NULL,
        ->   `L_PictureCount` int(4) NOT NULL,
        ->   PRIMARY KEY (`L_ListingID`)
        -> ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
    Query OK, 0 rows affected (0.21 sec)
    
    mysql> LOAD DATA LOCAL INFILE 'property_re_1.csv' 
        -> REPLACE INTO TABLE `markers`
        -> FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' ESCAPED BY '\\'
        -> LINES TERMINATED BY '\n' IGNORE 1 LINES;
    Query OK, 315 rows affected (0.01 sec)
    Records: 315  Deleted: 0  Skipped: 0  Warnings: 0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ive got this register script that puts the information into a mysql database. now
I'm working on a script that will check if a user is an Administrator
I am working on a script that converts a .txt file (non delimited) to
I am working on a script that parses a text file in an attempt
I am working on a script that will get the user name associated with
I am working on a script that downloads a file from Dropbox, supposed to
I'm working on a script that allows the user to draw with the mouse:
I am working on a script that fetches csv files from a web server.
I have working script that the user completes inputs on a form and when
Im working on a script that needs to find a match for certain letters(chords)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.