note 94515 deleted from function.fgets by danbrown
| From: | danbrown@php.net | Date: | Tue, 10 Nov 2009 02:22:19 +0000 |
| Subject: | note 94515 deleted from function.fgets by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-162682@lists.php.net to get a copy of this message | ||
Note Submitter: wcasado at live dot com
----
This option posted above worked really good for me for a very large file:
$filename = "../temp/file.txt";
$handle = @fopen($filename, "r");
//read from this line
$ic = 2300000;
//read to this line
$ic_max = 2600000; // stops after this number of rows
if ($handle) {
while (!feof($handle) && ++$ic<=$ic_max) {
$line = fgets($handle);
$final_line = explode("|",$line);
//echo "<br>".$final_line[0]. '|' .$final_line[1]. '|'
.$final_line[2];
if(!mysql_query("INSERT INTO table (ID, name, comercial_name) VALUES
('','$final_line[0]', '$final_line[1]',
'$final_line[2]')")) {
fclose($handle);
die($link->sql_error() .
"<br>The connection to the DB fail. (populateTAble).<br>"); }
}
fclose($handle);
}