tallaljamshed
1 week ago

using mysql load data query as a raw laravel query

Posted 1 week ago by tallaljamshed

Hi im trying to use this query

LOAD DATA INFILE 'c:/tmp/discounts.csv' 
INTO TABLE discounts 
FIELDS TERMINATED BY ',' 
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 ROWS;

in laravel as raw query but that line terminating character actually takes the query on new line and it does not work .

$upload = DB::raw("LOAD DATA INFILE '$file' INTO TABLE '$request->table' FIELDS TERMINATED by ',' LINES TERMINATED BY '\n' IGNORE 1 ROWS");

this is the error

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''teachertest' FIELDS TERMINATED by ',' LINES TERMINATED BY ' ' IGNORE 1 ROWS' at line 1 

Please sign in or create an account to participate in this conversation.