Add data from file into MySQL

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sanjeevcis
    New Member
    • May 2007
    • 8

    Add data from file into MySQL

    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
  • devsusen
    New Member
    • Feb 2007
    • 136

    #2
    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

    Comment

    • sanjeevcis
      New Member
      • May 2007
      • 8

      #3
      Originally posted by devsusen
      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,can t i solve my problem by writing query LOAD DATA INFILE to mysql..??

      Sanjeev..

      Comment

      • devsusen
        New Member
        • Feb 2007
        • 136

        #4
        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

        Comment

        • Atli
          Recognized Expert Expert
          • Nov 2006
          • 5062

          #5
          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.

          Comment

          • Atli
            Recognized Expert Expert
            • Nov 2006
            • 5062

            #6
            I have edited the threads title to better describe its topic.
            Please read the Posting Guidlines before posting.

            MODERATOR

            Comment

            Working...