Przeglądaj źródła

黑体字数据库支持pg

visuddhinanda 4 lat temu
rodzic
commit
fd87c0afe7
2 zmienionych plików z 86 dodań i 79 usunięć
  1. 75 68
      app/install/db_insert_bold.php
  2. 11 11
      app/search/bold_search.php

+ 75 - 68
app/install/db_insert_bold.php

@@ -12,8 +12,8 @@ require_once "install_head.php";
 生成黑体字数据库。黑体字多数是义注复注里的单词(尤其是专有名词)解释。
 </div>
 <?php
-include "./_pdo.php";
-include "../path.php";
+require_once "./_pdo.php";
+require_once "../path.php";
 
 if (isset($_GET["from"]) == false) {
     ?>
@@ -26,8 +26,8 @@ To: <input type="text" name="to" value="216"><br>
 return;
 }
 
-$from = $_GET["from"];
-$to = $_GET["to"];
+$from = (int)$_GET["from"];
+$to = (int)$_GET["to"];
 $filelist = array();
 $fileNums = 0;
 $log = "";
@@ -84,8 +84,8 @@ echo "doing:" . $xmlfile . "<br>";
 $log = $log . "$from,$FileName,open\r\n";
 
 $arrInserString = array();
-$db_file = _FILE_DB_BOLD_;
-PDO_Connect("$db_file");
+
+
 
 // 打开文件并读取数据
 if (($fp = fopen($dirXmlBase . $dirXml . $outputFileNameHead . ".csv", "r")) !== false) {
@@ -95,73 +95,80 @@ if (($fp = fopen($dirXmlBase . $dirXml . $outputFileNameHead . ".csv", "r")) !==
     }
     fclose($fp);
     echo "单词表load:" . $dirXmlBase . $dirXml . $outputFileNameHead . ".csv<br>";
+
+	PDO_Connect(_FILE_DB_BOLD_);
+
+	$query = "DELETE FROM "._TABLE_WORD_BOLD_." WHERE book=?";
+	PDO_Execute($query,array($from+1));
+	// 开始一个事务,关闭自动提交
+	$PDO->beginTransaction();
+	$query = "INSERT INTO "._TABLE_WORD_BOLD_." (book , paragraph , word , word2 , word_en ) VALUES (?,?,?,?,?)";
+	$stmt = $PDO->prepare($query);
+	$allcount = 1;
+	$count = 0;
+	$count1 = 0;
+	$sen = "";
+	$sen1 = "";
+	$sen_en = "";
+	$sen_count = 0;
+	$book = "";
+	$paragraph = "";
+	foreach ($arrInserString as $oneParam) {
+		if ($oneParam[15] == "bld") {
+			if ($oneParam[5] != "") {
+				$sen_count++;
+			}
+			$sen .= $oneParam[4] . " ";
+			$sen1 .= $oneParam[5] . " ";
+			$book = substr($oneParam[2], 1);
+			$paragraph = $oneParam[3];
+			if ($oneParam[5] != "") {
+				$newWord = array($book, $paragraph, $oneParam[4], $oneParam[5], getWordEn($oneParam[5]));
+				$stmt->execute($newWord);
+				$count++;
+				$allcount++;
+			}
+		} else {
+			if ($sen_count > 1) {
+				$sen = rtrim($sen);
+				$sen1 = rtrim($sen1);
+				$sen_en = getWordEn($sen1);
+				$newWord = array($book, $paragraph, $sen, $sen1, $sen_en);
+				$stmt->execute($newWord);
+				$count1++;
+				$allcount++;
+				$sen = "";
+				$sen1 = "";
+				$sen_en = "";
+				$sen_count = 0;
+			} else {
+				$sen = "";
+				$sen1 = "";
+				$sen_en = "";
+				$sen_count = 0;
+			}
+		}
+	}
+	// 提交更改
+	$PDO->commit();
+	if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
+		$error = PDO_ErrorInfo();
+		echo "error - $error[2] <br>";
+
+		$log = $log . "$from, $FileName, error, $error[2] \r\n";
+	} else {
+		echo "updata $count-$count1 recorders.";
+	}
+
+	$myLogFile = fopen($dirLog . "insert_bold.log", "a");
+	fwrite($myLogFile, $log);
+	fclose($myLogFile);
+	
 } else {
     echo "can not open csv file. filename=" . $dirXmlBase . $dirXml . $outputFileNameHead . ".csv";
 }
 
-// 开始一个事务,关闭自动提交
-$PDO->beginTransaction();
-$query = "INSERT INTO bold ('id','book','paragraph','word','word2','word_en') VALUES (NULL,?,?,?,?,?)";
-$stmt = $PDO->prepare($query);
-$allcount = 1;
-$count = 0;
-$count1 = 0;
-$sen = "";
-$sen1 = "";
-$sen_en = "";
-$sen_count = 0;
-$book = "";
-$paragraph = "";
-foreach ($arrInserString as $oneParam) {
-    if ($oneParam[15] == "bld") {
-        if ($oneParam[5] != "") {
-            $sen_count++;
-        }
-        $sen .= $oneParam[4] . " ";
-        $sen1 .= $oneParam[5] . " ";
-        $book = substr($oneParam[2], 1);
-        $paragraph = $oneParam[3];
-        if ($oneParam[5] != "") {
-            $newWord = array($book, $paragraph, $oneParam[4], $oneParam[5], getWordEn($oneParam[5]));
-            $stmt->execute($newWord);
-            $count++;
-            $allcount++;
-        }
-    } else {
-        if ($sen_count > 1) {
-            $sen = rtrim($sen);
-            $sen1 = rtrim($sen1);
-            $sen_en = getWordEn($sen1);
-            $newWord = array($book, $paragraph, $sen, $sen1, $sen_en);
-            $stmt->execute($newWord);
-            $count1++;
-            $allcount++;
-            $sen = "";
-            $sen1 = "";
-            $sen_en = "";
-            $sen_count = 0;
-        } else {
-            $sen = "";
-            $sen1 = "";
-            $sen_en = "";
-            $sen_count = 0;
-        }
-    }
-}
-// 提交更改
-$PDO->commit();
-if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
-    $error = PDO_ErrorInfo();
-    echo "error - $error[2] <br>";
-
-    $log = $log . "$from, $FileName, error, $error[2] \r\n";
-} else {
-    echo "updata $count-$count1 recorders.";
-}
 
-$myLogFile = fopen($dirLog . "insert_bold.log", "a");
-fwrite($myLogFile, $log);
-fclose($myLogFile);
 ?>
 
 

+ 11 - 11
app/search/bold_search.php

@@ -21,7 +21,7 @@ switch ($op) {
     case "pre": //预查询
         PDO_Connect(_FILE_DB_REF_INDEX_);
         echo "<div>";
-        $query = "select word,count from dict where \"eword\" like " . $PDO->quote($word . '%') . " OR \"word\" like " . $PDO->quote($word . '%') . "  limit 0,20";
+        $query = "SELECT word,count from dict where \"eword\" like " . $PDO->quote($word . '%') . " OR \"word\" like " . $PDO->quote($word . '%') . "  limit 20";
 
         $Fetch = PDO_FetchAll($query);
         $iFetch = count($Fetch);
@@ -83,7 +83,7 @@ switch ($op) {
 
         PDO_Connect(_FILE_DB_BOLD_);
         //查询符合的记录数
-        $query = "select count(*) as co from bold where \"word2\" in  $strQueryWord";
+        $query = "SELECT count(*) as co from "._TABLE_WORD_BOLD_." where \"word2\" in  $strQueryWord";
         $Fetch = PDO_FetchOne($query);
         if ($Fetch > 0) {
             $strDictTab .= "<li id=\"dt_bold\"  onclick=\"tab_click('dict_bold','dt_bold')\">{$_local->gui->vannana}({$Fetch})</li>";
@@ -100,7 +100,7 @@ switch ($op) {
             $strQueryWord中是所有可能的拼写
              */
             $realQueryWord = "(";
-            $query = "select word2,count(word) as co from bold where \"word2\" in $strQueryWord group by word2 order by co DESC";
+            $query = "SELECT word2,count(word) as co from "._TABLE_WORD_BOLD_." where \"word2\" in $strQueryWord group by word2 order by co DESC";
             $Fetch = PDO_FetchAll($query);
             $iFetch = count($Fetch);
             if ($iFetch > 0) {
@@ -121,7 +121,7 @@ switch ($op) {
             }
 
             //查找这些词出现在哪些书中
-            $query = "select book,count(word) as co from bold where \"word2\" in $realQueryWord group by book order by co DESC";
+            $query = "SELECT book,count(word) as co from "._TABLE_WORD_BOLD_." where \"word2\" in $realQueryWord group by book order by co DESC";
             $Fetch = PDO_FetchAll($query);
             $iFetch = count($Fetch);
             if ($iFetch > 0) {
@@ -146,7 +146,7 @@ switch ($op) {
             //黑体字主显示区右侧开始
             echo "<div id=\"dict_bold_right\" style='flex:7;'>";
             //前20条记录
-            $query = "select * from bold where \"word2\" in $realQueryWord limit 0,20";
+            $query = "SELECT * from "._TABLE_WORD_BOLD_." where \"word2\" in $realQueryWord limit 20";
             $Fetch = PDO_FetchAll($query);
             $iFetch = count($Fetch);
             if ($iFetch > 0) {
@@ -168,7 +168,7 @@ switch ($op) {
                         echo "<div class='mean'>$pali</div>";
                     } else {
                         //PDO_Connect(_FILE_DB_PALITEXT_);
-                        $query = "select * from "._TABLE_PALI_TEXT_." where \"book\" = '{$book}' and \"paragraph\" = '{$paragraph}' limit 0,20";
+                        $query = "SELECT * from "._TABLE_PALI_TEXT_." where \"book\" = '{$book}' and \"paragraph\" = '{$paragraph}' limit 20";
                         $FetchPaliText = PDO_FetchAll($query);
                         $countPaliText = count($FetchPaliText);
                         if ($countPaliText > 0) {
@@ -179,7 +179,7 @@ switch ($op) {
                                 $deep = 0;
                                 $sFirstParentTitle = "";
                                 while ($parent > -1) {
-                                    $query = "select * from pali_text where \"book\" = '{$book}' and \"paragraph\" = '{$parent}' limit 0,1";
+                                    $query = "SELECT * from pali_text where \"book\" = '{$book}' and \"paragraph\" = '{$parent}' limit 1";
                                     $FetParent = PDO_FetchAll($query);
                                     if ($sFirstParentTitle == "") {
                                         $sFirstParentTitle = $FetParent[0]["toc"];
@@ -273,7 +273,7 @@ switch ($op) {
                 }
 
                 //查找这些词出现在哪些书中
-                $query = "select book,count(word) as co from bold where \"word2\" in $wordlist group by book order by co DESC";
+                $query = "SELECT book,count(word) as co from "._TABLE_WORD_BOLD_." where \"word2\" in $wordlist group by book order by co DESC";
                 $Fetch = PDO_FetchAll($query);
                 $iFetch = count($Fetch);
                 if ($iFetch > 0) {
@@ -301,7 +301,7 @@ switch ($op) {
                 if ($booklist == "()") {
                     echo "<div>请选择书名</div>";
                 }
-                $query = "select * from bold where \"word2\" in $wordlist and \"book\" in $booklist  limit 0,20";
+                $query = "SELECT * from "._TABLE_WORD_BOLD_." where \"word2\" in $wordlist and \"book\" in $booklist  limit 20";
                 $Fetch = PDO_FetchAll($query);
                 $iFetch = count($Fetch);
                 if ($iFetch > 0) {
@@ -324,7 +324,7 @@ switch ($op) {
                             echo "<div class='mean'>$pali</div>";
                         } else {
                             PDO_Connect(_FILE_DB_PALITEXT_);
-                            $query = "select * from "._TABLE_PALI_TEXT_." where \"book\" = '{$book}' and \"paragraph\" = '{$paragraph}' limit 0,20";
+                            $query = "SELECT * from "._TABLE_PALI_TEXT_." where \"book\" = '{$book}' and \"paragraph\" = '{$paragraph}' limit 20";
                             $FetchPaliText = PDO_FetchAll($query);
                             $countPaliText = count($FetchPaliText);
                             if ($countPaliText > 0) {
@@ -335,7 +335,7 @@ switch ($op) {
                                     $deep = 0;
                                     $sFirstParentTitle = "";
                                     while ($parent > -1) {
-                                        $query = "select * from "._TABLE_PALI_TEXT_." where \"book\" = '{$book}' and \"paragraph\" = '{$parent}' limit 0,1";
+                                        $query = "SELECT * from "._TABLE_PALI_TEXT_." where \"book\" = '{$book}' and \"paragraph\" = '{$parent}' limit 1";
                                         $FetParent = PDO_FetchAll($query);
                                         if ($sFirstParentTitle == "") {
                                             $sFirstParentTitle = $FetParent[0]["toc"];