Insert to Index

From:
To:
doing : No.{$from} book "; global $dbh_word_index; $dns = "" . _FILE_DB_BOOK_WORD_; $dbh_word_index = new PDO($dns, "", "", array(PDO::ATTR_PERSISTENT => true)); $dbh_word_index->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); if (($handle = fopen("filelist.csv", 'r')) !== false) { while (($filelist[$fileNums] = fgetcsv($handle, 0, ',')) !== false) { $fileNums++; } } if ($to == 0 || $to >= $fileNums) { $to = $fileNums - 1; } $bookword = array(); if (($fpoutput = fopen(_DIR_CSV_PALI_CANON_WORD_ . "/{$from}_words.csv", "r")) !== false) { $count = 0; while (($data = fgetcsv($fpoutput, 0, ',')) !== false) { $book = $data[1]; if (isset($bookword[$data[3]])) { $bookword[$data[3]]++; } else { $bookword[$data[3]] = 1; } $count++; } } // 开始一个事务,关闭自动提交 $dbh_word_index->beginTransaction(); $query = "INSERT INTO "._TABLE_BOOK_WORD_." ('book','wordindex','count') VALUES ( ? , ? , ? )"; $stmt = $dbh_word_index->prepare($query); foreach ($bookword as $key => $value) { $stmt->execute(array($book, $key, $value)); } // 提交更改 $dbh_word_index->commit(); if (!$stmt || ($stmt && $stmt->errorCode() != 0)) { $error = $dbh_word_index->errorInfo(); echo "error - $error[2]
"; $log .= "$from, $FileName, error, $error[2] \r\n"; } else { echo "updata $count recorders.
"; $log .= "updata $count recorders.\r\n"; } $myLogFile = fopen($dirLog . "insert_index.log", "a"); fwrite($myLogFile, $log); fclose($myLogFile); if ($from >= $to) { echo "

齐活!功德无量!all done!

"; } else { echo ""; echo "正在载入:" . ($from + 1) . "——" . $filelist[$from + 1][0]; } ?>