将 170w行的txt文件.按行把数据导入到数据库中.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| header ( "Content-type: text/html;charset=utf-8" ); set_time_limit(0); include('Database.class.php'); $db = new Database('127.0.0.1', 'root', 'root', 'test'); $fp = fopen('171w.txt', 'r'); $i=1; $array = array();
function callback($now) { global $db, $array, $i, $fp; if(empty($array)) { while (!feof($fp)) { if($i == $now) { for($j=$i;$j<=$i+999;$j++) { $array[$j] = stream_get_line($fp, 1000000, "\n"); } break; } stream_get_line($fp, 1000000, "\n"); $i++; } } $db->insert("INSERT INTO test(name) VALUES('{$array[$now]}')"); } include('SkiyoProcess.class.php'); $sp = new SkiyoProcess(2, 1000, 171000); $sp->process('callback');
|
原文:http://blogread.cn/it/article/1825?f=wb