step2.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. require_once "install_head.php";
  3. ?>
  4. <html>
  5. <head>
  6. </head>
  7. <body>
  8. <style>
  9. #step2{
  10. background-color: #f1e7a4;
  11. }
  12. </style>
  13. <?php
  14. require_once 'nav_bar.php';
  15. ?>
  16. <h3>Step 2 Create User Database</h3>
  17. <?php
  18. $dbfile[] = array(_FILE_DB_USER_WBW_, "user_wbw.sql");
  19. $dbfile[] = array(_FILE_DB_COMMENTS_, "comments.sql");
  20. $dbfile[] = array(_FILE_DB_SENTENCE_, "sentence.sql");
  21. $dbfile[] = array(_FILE_DB_TERM_, "dhammaterm.sql");
  22. $dbfile[] = array(_FILE_DB_GROUP_, "group.sql");
  23. $dbfile[] = array(_FILE_DB_USERINFO_, "userinfo.sql");
  24. $dbfile[] = array(_FILE_DB_FILEINDEX_, "fileindex.sql");
  25. $dbfile[] = array(_FILE_DB_WBW_, "wbw.sql");
  26. $dbfile[] = array(_FILE_DB_COURSE_, "course.sql");
  27. $dbfile[] = array(_FILE_DB_MEDIA_, "media.sql");
  28. $dbfile[] = array(_FILE_DB_MESSAGE_, "message.sql");
  29. $dbfile[] = array(_FILE_DB_USER_STATISTICS_, "statistics.sql");
  30. $dir = "./userdb/";
  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="step2.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="step2.php?index=' . $i . '">重建</a><span style="color:red;">注意!此操作将删除原数据库中所有数据!</span></div>';
  60. }
  61. echo "</div>";
  62. }
  63. ?>
  64. <div>
  65. </div>
  66. <hr>
  67. <h2 style="text-align:center;"><a href="step3.php">Next</a></h2>
  68. </body>
  69. </html>