By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,216 Members | 1,001 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,216 IT Pros & Developers. It's quick & easy.

Add data from file into MySQL

P: 8
hi, i am new member to this site and to php as well.
My problem is :
i have the data in the text file like below way
ID : 1001
Name : kumar
Phone : 111111

ID : 1002
Name : keerthana
Phone : 111111
.
.
.
i just want to enter this data into backend in respective fields ID,NAME,PHONE, And I am unable to write a query for this.

Could any body help me ..
Sanjeev
May 9 '07 #1
Share this Question
Share on Google+
5 Replies


100+
P: 136
Hi,

u need to learn file handling functions, string function and MySql function to do this code.

Firstly u need to read the file into string then u need to split the string into array on the basis of delemeter - '\r\n\r\n'. Then u can get each block of id, name and phone number. they have to be splited again to get each value. After getting the values u can put them in backend.

susen
May 9 '07 #2

P: 8
Hi,

u need to learn file handling functions, string function and MySql function to do this code.

Firstly u need to read the file into string then u need to split the string into array on the basis of delemeter - '\r\n\r\n'. Then u can get each block of id, name and phone number. they have to be splited again to get each value. After getting the values u can put them in backend.

susen
Thank you Susen ,
your suggession is obsolutely correct,but,cant i solve my problem by writing query LOAD DATA INFILE to mysql..??

Sanjeev..
May 9 '07 #3

100+
P: 136
Hi,

I am sorry to say that u can't use the LOAD DATA INFILE to upload ur data. The reason is the format u have used in ur text file won't be supported by MySql.

The format of the text file that r used in LOAD DATA INFILE contains only the data separated by some separator. Again each row is separated by another separator ( mostly we use newline char.)

susen
May 11 '07 #4

Atli
Expert 5K+
P: 5,058
If you want to add the data from your text file into the database, you will either have to convert the file into something the built in MySQL functions will understand, or create your own script to parse the file into an array and insert the data using queries, like you would with any data.

Either way, you will have to build a code to re-format your existing data file.
May 11 '07 #5

Atli
Expert 5K+
P: 5,058
I have edited the threads title to better describe its topic.
Please read the Posting Guidlines before posting.

MODERATOR
May 11 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.