Link to home
Start Free TrialLog in
Avatar of austenr
austenr

asked on

Parse text file to mySQL problem

I need to load a comma delimited text file into mySQL that looks like this:

Field 1   I&D,COMP,POSTOP WOUND INF


Field 2  11200

Field 3  15.54

Field 4  256.32

Field 1 is a description and the commas must be left intact.  I am using the following code now:

<?php

//mysql_connect("localhost");

//mysql_select_db("cpdata" user="root" password=" ");
$link = mysql_connect('localhost', 'root', '');
if (!$link) {
    die('Not connected : ' . mysql_error());
}

// make cpdata the current db
$db_selected = mysql_select_db('cpdata', $link);
if (!$db_selected) {
    die ('Can\'t use cpdata : ' . mysql_error());
}

//mysql_query("LOAD DATA LOCAL INFILE '/Webcdm.csv'
mysql_query("LOAD DATA INFILE '/wamp/www/Webcdm.csv'
INTO TABLE test
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
(description,defaultcpt,industrial,federal,other)") or die ("Query failed: " . mysql_error());

?>

What do I have to do in order to keep the integrity of field 1 intact instead of the program parsing the characters after the comma to the next field?
ASKER CERTIFIED SOLUTION
Avatar of hernst42
hernst42
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial