MYSQL command string being cut - mysql

i have this code on my program
strSQL = "load data local infile 'C:/csv.csv' replace into table student_records fields terminated by ',' enclosed by '"' lines terminated by '\r\n'"
but the string it considers is only "load data local infile 'C:/csv.csv' replace into table student_records fields terminated by ',' enclosed by '"
and this is considered a comment' lines terminated by '\r\n'"
the string is being terminated by the double quote while it is still part of my mysql command.
can you give me another way around on how to do this?
i'm trying to automate the updating of data in my table.

Try escaping double quotes with "\" character:
strSQL = "load data local infile 'C:/csv.csv' replace into table student_records fields terminated by ',' enclosed by '\"' lines terminated by '\r\n'"

Related

Load data infile ignore 1 lines skip 2 lines

I want to import a CSV file to my MySQL table using Load data infile, but sometimes it skips 2 lines.
My SQL:
LOAD DATA LOW_PRIORITY LOCAL INFILE 'C:\\csv\\member.csv'
REPLACE INTO TABLE `member`
CHARACTER SET utf8mb4 FIELDS
TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
ESCAPED BY '"'
LINES TERMINATED BY '\r\n'
IGNORE 1 LINES (`UserName`, `RegDate`, `Address`, `Remark`);
Data:
"UserName","RegDate","Address","Remark"
"Peter",07-AUG-2001 18:17,"10th Floor, xxx's PlazaI","Remark xxx" xxx"
"Mary",07-NOV-2001 15:17,,"The ""BIG"" boss"
"Paul",07-DEC-2001 15:17,"10th Floor, xxx's PlazaI",""

LINES TERMINATED BY '\n' not working when store mysl result in txt file

When I try to store mysql result in txt file lines terminated is not working
select * from users INTO OUTFILE '/var/lib/mysql-
files/users.txt'
FIELDS TERMINATED BY '|'
ENCLOSED BY '"'
LINES TERMINATED BY '\n';---> not working
the result are all in one line
"1"|"John#test.com"|"20"|"John"|"test"/"2"|"omar#test.com"|"21"|"Omar"|"test2""3"|"Mytest#test.com"|"30"|"Mytest"|"test3"

How to use OUTFILE in codeigniter

I am trying to download the million of records from the database using OUTFILE. I am getting this error
Error Number: 1290
The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
SELECT name, cp_id FROM campaign INTO OUTFILE '/var/www/html/test_csv/1184445179_180912015611.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY ' ';
Filename: models/Admin_model.php
Line Number: 976
below is the model code:
$pth = rand().'_'.date('ymdhis').'.'.'csv';
$path = $_SERVER['DOCUMENT_ROOT'].'/test_csv/'.$pth;
$ad = $this->db->query("SELECT name, cp_id FROM campaign INTO OUTFILE '$path' FIELDS TERMINATED BY ',' ENCLOSED BY '\"' LINES TERMINATED BY '\n';")

Filter and export mysql data by script

SELECT siirMisralari_txt
INTO OUTFILE 'C:/Users/Nikel/Desktop/mIRC_02/siir_07.txt'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
ESCAPED BY '\\'
LINES TERMINATED BY '$crlf'
FROM `siirler`
WHERE `siirAdi_txt`
LIKE '%Ağustos Şiiri%'
this creates an empty file. why?

mysql & INTO OUTFILE - escape or replace new lines in data

I have the following sql statement to out put a sql table to a csv file.
Some data found in the column 'content' includes new line charactors which is causing issues, is there a way to replace all \n with 's?
SELECT id, title, content
INTO OUTFILE '/content.csv'
FIELDS TERMINATED BY ',' ESCAPED BY '\\' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
FROM content
REPLACE( IFNULL(content , ''), '\n' , '<br/>' ) as content
Try:
SELECT id, title, REPLACE(content , CHR(13), ' ') as content
INTO OUTFILE '/content.csv'
FIELDS TERMINATED BY ',' ESCAPED BY '\\' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
FROM content
where CHR(13) represents new line.