Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

passing data from text file in to mysql database?

Posted on 2002-07-24
3
Medium Priority
?
217 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 135 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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

719 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