How do I read this text file and Insert into MySQL?

前端 未结 5 713
萌比男神i
萌比男神i 2020-12-18 16:07

sample

user id  User Name
   U456      Mathew 
   U457      Leon
   U458      Cris
   U459      Yancy
   U460      Jane

and so on up to 500

5条回答
  •  感动是毒
    2020-12-18 17:02

    Depends. If the two fields are separated using a TAB character, then fgetcsv($f,1000,"\t") would work to read in each line. Otherwise use substr() if it's a fixed width column text file to split up the fields (apply trim() eventually).

    Loop over the rows and fields, and use your database interface of choice:

    db("INSERT INTO tbl (user_id, user_name) VALUES (?,?)", $row);
    

提交回复
热议问题