Jump to content

How to handle a " in PHP files / LOAD ATA IN FILE


SalientAnimal
Go to solution Solved by requinix,

Recommended Posts

Hi All,

 

I am running a PHP script on a daily basis to import data into my database. THe PHP file is executed by my Windows Services.

The PHP file is a LOAD DATA IN FILE script and looks like the below:

LOAD DATA LOCAL INFILE '\master_import\\myfilename.csv' IGNORE
INTO TABLE mydatabase.mytable
CHARACTER SET latin1
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
IGNORE 1 LINES
(
record_number
, name
, action_date
, location
, type_of_outlet
....
)
;

The ENCLOSED BY '"' is where my problem lies, as I do not know how to use the '"' without PHP reading it as a " to close the script.

 

Any help will be appreciated. Thanks.

 

Edited by SalientAnimal
Link to comment
Share on other sites

You don't know about backslashes? How do you not know about backslashes?

echo "String with a " quote"; // nope
echo "String with a \" quote"; // winner

Somehow with my brain working overtime and not being a seasoned php script writer I didn't even think of doing this, although I know I have done it in the past.

 

Thanks...

Edited by SalientAnimal
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.