Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 218
  • Last Modified:

passing data from text file in to mysql database?

hai all,

I wanted to pass data from from txt file in to mysql db.
the data is testing results of few boards(tested) in which I have serial number of the board,few testing parameters,& result=Fail or Pass.

my requirement is as follows:-
1)I need to read each line of the data in txt file
2)then have to check whether that particular board already exists in the database
  if it already exists check for fail or pass status in db.
  if(fail)
    then the current line of data should overwrite the existing data in db.
  if(pass)
    then the current line of data should be added in to db.
3)this loop should be done until end of the txt file.

can I do this way of overwriting & adding data from text file line by line.
if possible can anyone suggest me the way to resolve it.

The problem now I feel I would face is, all the while I pass the whole data in to db by following query
 "load data infile '".$path."".$category.".tmp' into table ".$category." fields terminated by\",\";"

but if I wanted to add data & overwrite data(if any) line by line in to db how to go about it.

if any one could suggest me!!!!!!! pls kindly do that.

Thank u
manju





0
manju70
Asked:
manju70
1 Solution
 
lokeshvCommented:
ofcourse u can do it by this way...

and u know the algo ...u just ned to write the code.

read file line by line(by fgets or u can read the entire file into a array by file function ) n do as ur algo...

or if ur file is CSV file then u can fgetcsv also..

after that i think u can write the code...just if and else loops..


if get into any trouble please..post here...

Regards,
Lk
0
 
manju70Author Commented:
csv file meanssssss!!!!!!!
manju
0
 
Richard QuadlingSenior Software DeverloperCommented:
CSV = Comma Seperated Variable.

These files are relative OK. The things to watch out for is having a ',' as part of the data.

e.g.

Board = GJ21
Test = a
Pass = True

In a CSV file, this could look like ...

GJ21,a,True

If the board name was GJ21,FF44, then the CSV file would look like ...

GJ21,FF44,a,True

The problem with this is that there is no immediate way of determining the position of the 3 fields as the CSV file has 4 fields in it.

Normally, you would have " around the text fields ...

"GJ21,FF44",a,True

This now works fine and most, if not all, CSV importers SHOULD deal with this correctly.

Another option is to use a Fixed length file.

In this format, you say that the board name is a maximum of 20 letters, the test is a max of 4 letters and the true/false is represented as T or F ...

12345678901234567890123451
GJ21,FF44           a    T
jlkdskfjsldfsdfj sdfXXXXXF

Other people use the TAB character to seperate the fields (a TABBED file). You COULD use an XML file too.

Many choices.

The easiest is probably the fixed length file as you simply hardcode the lengths. No need to worry about commas or quotes.



0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now