CSV import to MySQL character (comma) escape issue

Peruttu Julkaistu Jan 18, 2010 Maksettu toimituksen yhteydessä
Peruttu Maksettu toimituksen yhteydessä

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";

}

}

PHP

Projektin tunnus: #592961

Tietoa projektista

8 ehdotusta Etäprojekti Aktiivinen Jan 27, 2010

8 freelanceria on tarjonnut keskimäärin $38 tähän työhön

TakeReal

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.

$40 USD 1 päivässä
(1254 arvostelua)
7.5
DesignSolutionSW

Please check PM.Thanks.

$30 USD 0 päivässä
(57 arvostelua)
7.0
onready

I am ready & available.

$45 USD 0 päivässä
(39 arvostelua)
5.1
msgaruba

please read pmb thansk

$30 USD 1 päivässä
(13 arvostelua)
4.2
skilledsir

hello.i am skilled in mysql and php.i can start it right now.

$30 USD 0 päivässä
(15 arvostelua)
3.7
khushigupta

dear... can u send me the demo link for that

$70 USD 1 päivässä
(0 arvostelua)
0.0