db_insert_wordindex_from_csv.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. require_once "install_head.php";
  3. include "./_pdo.php";
  4. ?>
  5. <!DOCTYPE html>
  6. <html>
  7. <head>
  8. </head>
  9. <body>
  10. <h2>Insert to Index</h2>
  11. <?php
  12. if(isset($_GET["from"])==false){
  13. $from=0;
  14. }
  15. else{
  16. $from=$_GET["from"];
  17. }
  18. $dirLog=_DIR_LOG_."/";
  19. $filelist=array();
  20. $fileNums=0;
  21. $log="";
  22. echo "<h2>doing : No.{$from} </h2>";
  23. global $dbh_word_index;
  24. $dns = "sqlite:"._FILE_DB_WORD_INDEX_;
  25. $dbh_word_index = new PDO($dns, "", "",array(PDO::ATTR_PERSISTENT=>true));
  26. $dbh_word_index->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
  27. if(($fpoutput=fopen(_DIR_CSV_PALI_CANON_WORD_INDEX_."/{$from}.csv", "r"))!==FALSE){
  28. // 开始一个事务,关闭自动提交
  29. $dbh_word_index->beginTransaction();
  30. $query="INSERT INTO wordindex ('id','word','word_en','count','normal','bold','is_base','len') VALUES (?,?,?,?,?,?,?,?)";
  31. $stmt = $dbh_word_index->prepare($query);
  32. $count=0;
  33. while(($data=fgetcsv($fpoutput,0,','))!==FALSE){
  34. $stmt->execute($data);
  35. $count++;
  36. }
  37. // 提交更改
  38. $dbh_word_index->commit();
  39. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  40. $error = $dbh_word_index->errorInfo();
  41. echo "error - $error[2] <br>";
  42. $log.="$from, $FileName, error, $error[2] \r\n";
  43. }
  44. else{
  45. echo "updata $count recorders.<br />";
  46. $log.="updata $count recorders.\r\n";
  47. }
  48. }
  49. else{
  50. echo "<h2>齐活!功德无量!all done!</h2>";
  51. exit;
  52. }
  53. echo "<script>";
  54. echo "window.location.assign(\"db_insert_wordindex_from_csv.php?from=".($from+1)."\")";
  55. echo "</script>";
  56. echo "正在载入:".($from+1)."——".$filelist[$from+1][0];
  57. ?>
  58. </body>
  59. </html>