所以这就是我正在做的事情。
- 在 for 循环中读取一行。(因为我是在共享主机中,所以一下子会占用一些资源。) 2.将正确的字段数据获取到变量中。3.根据提取的字段操作req数据。4.更新字段=提取数据的新字段。
另外一点,我正在将当前位置添加到文件中,以便脚本下次运行时可以从那里继续。
问题:它似乎不起作用。counter.txt 的值类似于 3-4,但它只是驻留在那里。我的数据库有 1000k 行。
我的代码:
require ("dbconnect.php");
header("refresh:29;url=process.php"); // so it doesnt ever end. I cant use max_execution_time here for some reason.
$count = mysql_query("SELECT COUNT(*) FROM collection ");
$data = mysql_fetch_array($count);
$count = $data[0];
echo $count;
$countfile = fopen("counter.txt", "r");
$counter = fgets($countfile);
echo fgets($countfile);
while (fgets($countfile) <= $count)
{
$i = fgets($countfile);
$takeword = mysql_query("SELECT word FROM collection WHERE id='$i'") or die();
$wd = mysql_fetch_array($takeword);
$data = $wd[0];
$d1 = hash($algorith='md2',$data);
$d2 = hash($algorith='md4',$data);
$write = mysql_query("UPDATE collection SET md2='$d1', md4='$d2' WHERE id='$i'") or die(mysql_error());
//opens, empties and write the new pointer to the file. closes, and open the file in readmode for the next read at the loop.
$counts = fopen("counter.txt", "w+");
fwrite($counts, $counter + 1);
fclose($counts);
$countfile = fopen("counter.txt", "r");
}
任何帮助将不胜感激:) 寻找代码优化并消除错误。建议会做。:)