step4.php 2.1 KB

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