Solved

passing data from text file in to mysql database?

Posted on 2002-07-24
3
212 Views
Last Modified: 2010-08-05
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
Comment
Question by:manju70
3 Comments
 
LVL 4

Expert Comment

by:lokeshv
ID: 7176355
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
 

Author Comment

by:manju70
ID: 7176515
csv file meanssssss!!!!!!!
manju
0
 
LVL 40

Accepted Solution

by:
Richard Quadling earned 45 total points
ID: 7176689
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to submit record from external php form to a Sharepoint list? 5 55
Help in good tutorials for PHP, HTML and CSS 6 41
Wordpress Security 29 49
jQuery force form POST 7 48
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question