step3_run.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <?php
  2. require_once '../path.php';
  3. $filename = $_GET["filename"];
  4. $dbname = $_GET["dbname"];
  5. $table = $_GET["table"];
  6. switch($_GET["dbtype"]){
  7. case "rich":
  8. case "system":
  9. if($_GET["dbtype"]=="rich"){
  10. $dbfilename = _DIR_DICT_TEXT_."/rich/{$dbname}";
  11. $sDescDbFile = _DIR_DICT_3RD_."/".$dbname;
  12. $csvfile = _DIR_DICT_TEXT_."/rich/{$filename}";
  13. }
  14. else if($_GET["dbtype"]=="system"){
  15. $dbfilename = _DIR_DICT_TEXT_."/system/{$dbname}";
  16. $sDescDbFile = _DIR_DICT_SYSTEM_."/".$dbname;
  17. $csvfile = _DIR_DICT_TEXT_."/system/{$filename}";
  18. }
  19. $dns = "sqlite:".$dbfilename;
  20. $dbh = new PDO($dns, "", "",array(PDO::ATTR_PERSISTENT=>true));
  21. $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
  22. if(strstr($filename,".",true)===strstr($dbname,".",true)){
  23. //建立数据库
  24. $_sql = file_get_contents('rich_dict.sql');
  25. $_arr = explode(';', $_sql);
  26. //执行sql语句
  27. foreach ($_arr as $_value) {
  28. $dbh->query($_value.';');
  29. }
  30. echo $dns."建立数据库成功<br>";
  31. }
  32. // 开始一个事务,关闭自动提交
  33. $dbh->beginTransaction();
  34. $query="INSERT INTO dict ('id','pali', 'type', 'gramma', 'parent', 'mean', 'note', 'parts', 'partmean', 'status', 'confidence', 'len', 'dict_name', 'lang') VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
  35. $stmt = $dbh->prepare($query);
  36. $count=0;
  37. // 打开文件并读取数据
  38. if(($fp=fopen($csvfile, "r"))!==FALSE){
  39. while(($data=fgetcsv($fp,0,','))!==FALSE){
  40. //id,wid,book,paragraph,word,real,type,gramma,mean,note,part,partmean,bmc,bmt,un,style,vri,sya,si,ka,pi,pa,kam
  41. $stmt->execute($data);
  42. $count++;
  43. }
  44. fclose($fp);
  45. echo "单词表load<br>";
  46. }
  47. else{
  48. echo "can not open csv file. ";
  49. }
  50. // 提交更改
  51. $dbh->commit();
  52. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  53. $error = $dbh->errorInfo();
  54. echo "error - $error[2] <br>";
  55. }
  56. else{
  57. echo "updata $count recorders.";
  58. }
  59. $dbh = null;
  60. if(copy($dbfilename,$sDescDbFile)){
  61. echo "文件复制成功<br>";
  62. }
  63. else{
  64. echo "文件复制失败<br>";
  65. }
  66. break;
  67. case "thin":
  68. $dbfilename = _DIR_DICT_TEXT_."/system/{$dbname}";
  69. $sDescDbFile = _DIR_DICT_SYSTEM_."/".$dbname;
  70. $csvfile = _DIR_DICT_TEXT_."/system/{$filename}";
  71. $dns = "sqlite:".$dbfilename;
  72. $dbh = new PDO($dns, "", "",array(PDO::ATTR_PERSISTENT=>true));
  73. $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
  74. // 开始一个事务,关闭自动提交
  75. $dbh->beginTransaction();
  76. if($dbname==="ref.db"){
  77. if($table==="dict"){
  78. $query="INSERT INTO {$table} ('id','pali', 'type', 'gramma', 'parent', 'mean', 'note', 'parts', 'partmean', 'status', 'confidence', 'len', 'dict_name', 'lang') VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
  79. }
  80. else if($table==="info"){
  81. $query="INSERT INTO {$table} ('id','pali', 'type', 'gramma', 'parent', 'mean', 'note', 'parts', 'partmean', 'status', 'confidence', 'len', 'dict_name', 'lang') VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
  82. }
  83. }
  84. else if($dbname==="ref1.db"){
  85. $query="INSERT INTO {$table} ('id','pali', 'type', 'gramma', 'parent', 'mean', 'note', 'parts', 'partmean', 'status', 'confidence', 'len', 'dict_name', 'lang') VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
  86. }
  87. $stmt = $dbh->prepare($query);
  88. $count=0;
  89. // 打开文件并读取数据
  90. if(($fp=fopen($csvfile, "r"))!==FALSE){
  91. while(($data=fgetcsv($fp,0,','))!==FALSE){
  92. $stmt->execute($data);
  93. $count++;
  94. }
  95. fclose($fp);
  96. echo "单词表load<br>";
  97. }
  98. else{
  99. echo "can not open csv file. ";
  100. }
  101. // 提交更改
  102. $dbh->commit();
  103. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  104. $error = $dbh->errorInfo();
  105. echo "error - $error[2] <br>";
  106. }
  107. else{
  108. echo "updata $count recorders.";
  109. }
  110. $dbh = null;
  111. if(copy($dbfilename,$sDescDbFile)){
  112. echo "文件复制成功<br>";
  113. }
  114. else{
  115. echo "文件复制失败<br>";
  116. }
  117. break;
  118. case "part":
  119. $dns = "sqlite:"._FILE_DB_part_;
  120. $dbh = new PDO($dns, "", "",array(PDO::ATTR_PERSISTENT=>true));
  121. $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
  122. {
  123. //建立数据库
  124. $_sql = file_get_contents('part.sql');
  125. $_arr = explode(';', $_sql);
  126. //执行sql语句
  127. foreach ($_arr as $_value) {
  128. $dbh->query($_value.';');
  129. }
  130. echo $dns."建立数据库成功<br>";
  131. }
  132. // 开始一个事务,关闭自动提交
  133. $dbh->beginTransaction();
  134. $query="INSERT INTO part ('word','weight') VALUES ( ?, ? )";
  135. $stmt = $dbh->prepare($query);
  136. $count=0;
  137. // 打开文件并读取数据
  138. if(($fp=fopen(_DIR_DICT_TEXT_."/system/part.csv", "r"))!==FALSE){
  139. while(($data=fgetcsv($fp,0,','))!==FALSE){
  140. //id,wid,book,paragraph,word,real,type,gramma,mean,note,part,partmean,bmc,bmt,un,style,vri,sya,si,ka,pi,pa,kam
  141. $stmt->execute($data);
  142. $count++;
  143. }
  144. fclose($fp);
  145. echo "part load ";
  146. }
  147. else{
  148. echo "can not open csv file. ";
  149. }
  150. // 提交更改
  151. $dbh->commit();
  152. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  153. $error = $dbh->errorInfo();
  154. echo "error - $error[2] <br>";
  155. }
  156. else{
  157. echo "updata $count recorders.";
  158. }
  159. $dbh = null;
  160. break;
  161. }
  162. ?>