CSV import to MySQL character (comma) escape issue
$30-250 USD
Paid on delivery
I need someone to fix this issue: the script below is supposed to load a csv file into my cooresponding database table, the data may contain any set of characters and not give errors when importing,
my issue is that i need to be able to save a csv file with commas as a part of the data, as well as any character, and still have it import correctly.
Sample csv format:
Column 1 Column 2 Column 3 Column 4 Column 5 Column 6
8 dataspecchar/*-+?><:; data3 data4 !@#$%^&*() data6
Script:
$target = "mycsvfile.csv";
$fcontents = file ($target);
$count=0;
for($i=0; $i<sizeof($fcontents); $i++) {
$line = trim($fcontents[$i]);
$arr = explode(",", $line);
$sql = "insert into products values ('".
implode("','", $arr) ."')";
mysql_query($sql);
$count++;
if(mysql_error()) {
echo mysql_error() ."<br>\n";
}
else{
$Status_Message = "CSV file imported, $count items added to the database";
}
}
Project ID: #592961
About the project
8 freelancers are bidding on average $38 for this job
Original script works if you don't use "," as part of field content, Right? Please, send me your CSV file. I will rewrite script to allow you import data with comma and other chars.