Jump to content

Add text file to mysql DB


snowman2344

Recommended Posts

I am trying to add a txt file to a mysql database. Is there any one that can help?

Here are the details

 

TEST.TXT

contains the following

 

A00120091001999999990000020000000000000000000000000000000000000000000000000

A00220091001999999990000061000000000000000000000000000000000000000000000000

A00320091001999999990000068750000000000000000000000000000000000000000000000

A00420091001999999990000033500000000000000000000000000000000000000000000000

A00520091001999999990000062650000000000000000000000000000000000000000000000

A00620070401999999990000042350000000000000000000000000000000000000000000000

A00720091001999999990000032350000000000000000000000000000000000000000000000

A00820070401999999990000010250000000000000000000000000000000000000000000000

And so on up to 200 rows long

 

I need to split each row the same way and add them to a table

I will use the first row as an example

Character 1 to 4 (A001) entered into a field called name

Character 5 to 12 (20091001) entered into a field called efdate

Character 13 to 20 (99999999) entered into a field called exdate

Character 21 to 31 (00000200000) entered into a field called prfee

Character 32 to 42 (00000000000) entered into a field called assfee

Character 43 to 53(00000000000) entered into a field called spfee

Character 54 to 64 (00000000000) entered into a field called anfee

Character 65 to 75 (00000000000) entered into a field called nanfee

 

Thanks in advance for the help

 

Link to comment
Share on other sites

Something like this(not tested):

$fs = fopen('TESTS.TXT', 'r');
while ($line = fgets($fs)) {
  $name = substr($line, 0, 4);
  $efdate = substr($line, 4, ;
  $exdate = substr($line, 12, ; 
// ... MORE LINES LIKE THAT
// NOTE: for substr() the the first character of the string is at position 0 (zero)

// DO SOMETHING WITH THE DATA
}
fclose($fs);

 

There are other ways to do this; like file() which will load the entire file into an array of lines.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.