step4.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. require_once '../path.php';
  3. ?>
  4. <html>
  5. <head>
  6. </head>
  7. <body>
  8. <h3>Step 4 三藏语料库</h3>
  9. <div style="margin:1em;background-color:#f1e7a4;">
  10. 生成三藏语料库
  11. </div>
  12. <div>
  13. <h4>生成数据库文件</h4>
  14. <?php
  15. $dbfile[]=array(_FILE_DB_BOLD_,"bold.sql");
  16. $dbfile[]=array(_FILE_DB_BOOK_WORD_,"bookword.sql");
  17. $dbfile[]=array(_FILE_DB_INDEX_,"index.sql");
  18. $dbfile[]=array(_FILE_DB_PALITEXT_,"pali_text.sql");
  19. $dbfile[]=array(_FILE_DB_PALI_INDEX_,"paliindex.sql");
  20. $dbfile[]=array(_FILE_DB_WORD_INDEX_,"wordindex.sql");
  21. $dir="./palicanon_db/";
  22. if(isset($_GET["index"])){
  23. echo '<div style="padding:10px;margin:5px;border-bottom: 1px solid gray;background-color:yellow;">';
  24. $index = $_GET["index"];
  25. $dns = "sqlite:".$dbfile[$index][0];
  26. $dbh = new PDO($dns, "", "",array(PDO::ATTR_PERSISTENT=>true));
  27. $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
  28. //建立数据库
  29. $_sql = file_get_contents($dir.$dbfile[$index][1]);
  30. $_arr = explode(';', $_sql);
  31. //执行sql语句
  32. foreach ($_arr as $_value) {
  33. $dbh->query($_value.';');
  34. }
  35. echo $dns."建立数据库成功";
  36. echo "</div>";
  37. }
  38. for($i=0; $i<count($dbfile); $i++){
  39. $db = $dbfile[$i];
  40. echo '<div style="padding:10px;margin:5px;border-bottom: 1px solid gray;display:flex;">';
  41. echo '<div style="flex:5;">'.$db[0].'</div>';
  42. echo '<div style="flex:3;">';
  43. if(!file_exists($db[0])){
  44. echo "<span style='color:red;'>数据库不存在</span>";
  45. echo "</div>";
  46. echo '<div style="flex:2;"><a href="step4.php?index='.$i.'">建立</a></div>';
  47. }
  48. else{
  49. echo "<span style='color:green;'>已存在</span>";
  50. echo "</div>";
  51. echo '<div style="flex:2;"><a href="step4.php?index='.$i.'">重建</a><span style="color:red;">注意!此操作将删除原数据库中所有数据!</span></div>';
  52. }
  53. echo "</div>";
  54. }
  55. ?>
  56. <hr>
  57. <h2><a href="step5.php">Next</a></h2>
  58. </body>
  59. </html>