Need php script for insert data in mysql from text file

Discussion in 'Programming/Scripts' started by Ahad, Jul 14, 2012.

  1. Ahad

    Ahad New Member

    I need a script which will read data from text file and insert it into mysql database.Please help me if you know the solution.here i attached my text file.
     

    Attached Files:

    • cdr.txt
      File size:
      3.7 KB
      Views:
      346
  2. falko

    falko Super Moderator Howtoforge Staff

    You can search for "csv to sql" on Google, there are a lot of scripts and online tools.
     
  3. dannypb

    dannypb New Member

    Hey Falko, tysm for all your ispconfig work :) . I recently got it working for my RHEL 6.3 server with your CentOS instructions. You are my hero!

    Ahad,

    if your server has phpmyadmin, that is one way enter it. With that text file though, you do not give enough information for anyone to enter it into a mysql table. They would need the table name and the fields names. One way you could easily do it yourself, is to cut and paste the insert information into that text file. Then sign into mysql at the command prompt, go to that data base and simply cut and paste the inserts. Here is the general format:

    insert into [TABLENAME] ('[FIELDNAME1]', [FIELDNAME2], ect...)
    values ('[FIELDDATA1]','[FIELDDATA2]', ect...);

    so it would look something like
    insert into customertable (cusid, cusname, cusaddress) values ('0', 'Joe', '123 Here St');

    the semi colon at the end is needed for every insert. Good luck :)
     

Share This Page