Forum Moderators: coopster
Are you saying you want to remove lines in a database?
you could make one pretty quickly.
I would write from your existing file to a new file if it really is that big so that you don't have to keep so much in memory.
<?
$srcfile = "/path/to/source/file.sql";
$destfile = "/path/to/destination/file.sql";
$sfp = fopen($srcfile,'r');
$dfp = fopen($destfile,'w');
// I used an array here, if you have more than one line to remove
// include all line numbers to remove seperated by commas
$lineskip = array(4114);
$linecount = 1;
// I don't know the size of the biggest row of data
// but just make the 1024 bigger if need be
while ($nextline = fgets($sfp,1024)) {
if(!in_array($linecount,$lineskip)) {
fwrite($nextline,$dfp);
}
$linecount++;
}
fclose($sfp);
fclose($dfp);
?>
something like that should work fine. Hopefully the file isn't so long that the script times out but it shouldn't.
While you're in the loop, however, after jatar_k's
if(!in_array($linecount,$lineskip)) {
fwrite($nextline,$dfp);
} consider throwing in an else statement like
else echo "'".$nextline."'<br>\n";
so you can see what the problem is with the line.
Then you can add an ereg_replace() to fix whatever is wrong, and run the script again, without losing any data. Like:
if(!in_array($linecount,$lineskip)) {
fwrite($nextline,$dfp);
}
else {
$nextline = ereg_replace('correction','problem',$nextline);
fwrite($nextline,$dfp);
}