瀏覽代碼

自动查词 一次打开所有数据表

visuddhinanda 5 年之前
父節點
當前提交
02ac498b13
共有 2 個文件被更改,包括 28 次插入6 次删除
  1. 0 2
      app/install/db_insert_page_index.php
  2. 28 4
      app/studio/dict_find_one.php

+ 0 - 2
app/install/db_insert_page_index.php

@@ -134,8 +134,6 @@ for($iFile=$from;$iFile<=$to;$iFile++){
 	else{
 		echo "can not open csv file. filename=".$dirXmlBase.$dirXml.$outputFileNameHead.".csv";
 	}
-	
-	
 }
 	echo "齐活!功德无量!all done!";	
 ?>

+ 28 - 4
app/studio/dict_find_one.php

@@ -89,6 +89,20 @@ else{
 	}
 }
 
+$_dict_db = array();
+foreach($db_file_list as $db_file){
+	try {
+		$dbh = new PDO("sqlite:".$db_file, "", "");
+		$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
+		$_dict_db[] = array("file"=>$db_file,"dbh"=>$dbh);
+
+	} catch (PDOException $e) {
+		if($debug){
+			print "Error!: " . $e->getMessage() . "<br/>";
+		}
+	}
+}
+
 for($i=0;$i<$lookup_loop;$i++)
 {
 	$parent_list=array();
@@ -102,11 +116,11 @@ for($i=0;$i<$lookup_loop;$i++)
 	if($debug){
 		echo "<h2>第".($i+1)."轮查询:".count($word_list)."</h2>";
 	}
-	foreach($db_file_list as $db_file){
+	foreach($_dict_db as $db_file){
 		if($debug){
-			echo "dict connect:$db_file<br>";
+			echo "dict connect:{$db_file["file"]}<br>";
 		}
-		PDO_Connect("sqlite:$db_file");	
+		//PDO_Connect("sqlite:".$db_file);
 		if($i==0){
 			$query = "select * from dict where \"pali\" in $strQueryWord ORDER BY rowid DESC";
 		}
@@ -116,7 +130,17 @@ for($i=0;$i<$lookup_loop;$i++)
 		if($debug){
 			echo $query."<br>";
 		}
-		$Fetch = PDO_FetchAll($query);
+		if($db_file["dbh"]){
+			$stmt = $db_file["dbh"]->query($query);
+			$Fetch = $stmt->fetchAll(PDO::FETCH_ASSOC);
+		}
+		else{
+			$Fetch = array();
+			if($debug){
+				echo "无效的数据库句柄";
+			}
+		}
+		//$Fetch = PDO_FetchAll($query);
 		$iFetch=count($Fetch);
 		if($debug){
 			echo "count:$iFetch<br>";