PHP reads the TXT file and inserts it into the database. there is a TXT file, which is about 300 MB or more. what should I do if I want PHP to read it and insert it into the database in different entries? the TXT file format is like this. What should I do? wangli & nbsp; # & nbsp; 20100203 & nbsp; # & nbsp; Li Si liwsi & nbsp; # & nbsp; 201 PHP reads TXT files and inserts them into the database
There is a TXT file, which is about 300 MB or more. what should I do if I want PHP to read the file and insert it into the database in multiple entries? the TXT file format is like this. What should I do?
Wangli #20100203 # Li Si
Liwsi #2015544 # xiaofen
Wangli #20100203 # Li Si
Liwsi #2015544 # xiaofen
Wangli #20100203 # Li Si
Liwsi #2015544 # xiaofen
Wangli #20100203 # Li Si
Liwsi #2015544 # xiaofen
Wangli #20100203 # Li Si
Liwsi #2015544 # xiaofen
Wangli #20100203 # Li Si
Liwsi #2015544 # xiaofen
I wrote this by myself, but it can only be read and retrieved and displayed, except that I don't know how to insert the database, and there is a line break in the TXT file, but there is a line break when PHP reads it, another problem is that if fread ($ data, 1000) is used, where 1000 refers to reading 1000 characters, what if one row and one row are needed. Now this TXT is like a row. if the TXT contains 1000 characters, it is possible that it only reads half a row.
$data='11.txt';
$files=fopen($data,"r");
$res=fread($files,100000);
echo $res.'
';
------ Solution --------------------
$ Data = '11.txt ';
$ Fp = fopen ($ data, 'r ');
While ($ r = fgets ($ fp )){
$ T = join ("','", explode ('#', $ r ));
$ SQL = "insert into table values ('$ t ')";
// Execute SQL
}
However, it seems that mysql should be completed using the load data infile command.