PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, August 29, 2022

[FIXED] How to import data from CSV file to MySql table only for selected columns and CSV has both values enclosed with " " and not enclosed with " "

 August 29, 2022     csv, database, mysql     No comments   

Issue

I have tried using this commands

LOAD DATA LOCAL INFILE '/home/cs/Documents/abc.csv' 
INTO TABLE whatsappmessages 
FIELDS TERMINATED BY ','  
IGNORE 1 ROWS  
(number,@Number,message,@Message) 
set createdtime=now();

It is inserting number column value correctly , But in message column few data which are enclosed with ""(double quotes) and after the comma(,) string is taking(ie: logo and details. Click https://xxxx.co/xyzop now!) and inserting not the full value , but without double quotes empty string is inserting(ie: second line) .

This is the CSV file content i have

1111111111,"MARKET YOUR STORE! Customize xxxxxx latest emailer featuring aaaa cccc with your store name, logo and details. Click https://xxxx.co/xyzop now!"
2222222222,MARKET YOUR STORE! By sharing xxxxxx stunning collection featuring aaaa cccc with your consumer database. Click https://xxxx.co/xyzop now!
2222222222,"MARKET YOUR STORE! Customize xxxxxx latest emailer featuring aaaa cccc with your store name, logo and details. Click https://xxxx.co/xyzop now!"
3333333333,MARKET YOUR STORE! By sharing xxxxxx stunning collection featuring aaaa cccc with your consumer database. Click https://xxxx.co/xyzop now!

Anyone knows how to solve this please help me out, Thanks!


Solution

try this


LOAD DATA LOCAL INFILE '/home/cs/Documents/abc.csv' 
  INTO TABLE whatsappmessages FIELDS TERMINATED BY ',' 
  OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\r\n' 
  IGNORE 1 ROWS (number, message) 
set 
  createdtime = now();



Answered By - walker624
Answer Checked By - Robin (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing