PHP reads TXT file into database
There is a TXT file, about 300 MB, want to read PHP, and then the sub-bar inserted into the database, what should be done, the TXT file format is probably the case. What should I do?
Wangli # 20100203 # John Doe
LIWSI # 2015544 # Xiaofen
Wangli # 20100203 # John Doe
LIWSI # 2015544 # Xiaofen
Wangli # 20100203 # John Doe
LIWSI # 2015544 # Xiaofen
Wangli # 20100203 # John Doe
LIWSI # 2015544 # Xiaofen
Wangli # 20100203 # John Doe
LIWSI # 2015544 # Xiaofen
Wangli # 20100203 # John Doe
LIWSI # 2015544 # Xiaofen
This is my own writing, but just can read out and display except, do not know how to insert the database, and TXT file is originally there is a line, but PHP read out there is a newline, there is a problem is if using fread ($data, 1000) This place is 1000 refers to reading 1000 characters, if you need a line of reading it. Now this txt is a line like this, if you say 1000 characters this way, it is possible to finally just read to 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 use the LOAD DATA INFILE command to complete