visuddhinanda před 4 roky
rodič
revize
5f8bce9582

+ 13 - 5
app/admin/word_index_weight_refresh.php

@@ -27,19 +27,26 @@ if (isset($_GET["from"])) {
 }
 
 $dh_word = new PDO( _PG_DB_WORD_INDEX_, _DB_USERNAME_, _DB_PASSWORD_);
-$dh_word->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
+$dh_word->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
 
 $dh_pali = new PDO( _PG_DB_PALI_INDEX_, _DB_USERNAME_, _DB_PASSWORD_);
-$dh_pali->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
+$dh_pali->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
 
 echo "from=$from to = $to \n";
 for ($i = $from; $i <= $to; $i++) {
     $time_start = microtime(true);
     echo "正在处理 book= $i ";
     $query = "SELECT max(paragraph) from "._PG_TABLE_WORD_." where book=?";
-	$stmt = $dh_pali->prepare($query);
-    $stmt->execute(array($i));
-    $row = $stmt->fetch(PDO::FETCH_NUM);
+	try {
+		//code...
+		$stmt = $dh_pali->prepare($query);
+		$stmt->execute(array($i));
+		$row = $stmt->fetch(PDO::FETCH_NUM);
+	}catch(PDOException $e){
+		fwrite(STDERR,"error:".$e->getMessage());
+		continue;
+	}
+
     if ($row) {
         $max_para = $row[0];
         echo "段落数量:$max_para ";
@@ -52,6 +59,7 @@ for ($i = $from; $i <= $to; $i++) {
             $query = "SELECT wordindex,count(*) as co from "._PG_TABLE_WORD_." where book={$i} and paragraph={$j} group by wordindex";
             $stmt = $dh_pali->query($query);
             $fetch_voc = $stmt->fetchAll(PDO::FETCH_ASSOC);
+			
             $vocabulary = array();
             foreach ($fetch_voc as $key => $value) {
                 $vocabulary[$value["wordindex"]] = $value["co"];

+ 14 - 3
app/install/db_insert_bookword_from_csv_cli.php

@@ -36,7 +36,7 @@ define("_TABLE_", "book_words");
 global $dbh_word_index;
 $dns = _DB_;
 $dbh_word_index = new PDO($dns, _DB_USERNAME_, _DB_PASSWORD_, array(PDO::ATTR_PERSISTENT => true));
-$dbh_word_index->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
+$dbh_word_index->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
 
 if (($handle = fopen(__DIR__."/filelist.csv", 'r')) !== false) {
     while (($filelist[$fileNums] = fgetcsv($handle, 0, ',')) !== false) {
@@ -68,7 +68,13 @@ for ($from=$_from-1; $from < $_to; $from++) {
     #删除原来的数据
     $query = "DELETE FROM "._TABLE_." WHERE book = ?";
     $stmt = $dbh_word_index->prepare($query);
-    $stmt->execute(array($book));
+	try{
+		$stmt->execute(array($book));
+	}catch(PDOException $e){
+		fwrite(STDERR,"error:".$e->getMessage());
+		continue;
+	}
+    
     if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
         $error = $dbh_word_index->errorInfo();
         echo "error - $error[2]".PHP_EOL;
@@ -80,7 +86,12 @@ for ($from=$_from-1; $from < $_to; $from++) {
         $stmt = $dbh_word_index->prepare($query);
 
         foreach ($bookword as $key => $value) {
-            $stmt->execute(array($book, $key, $value));
+			try{
+			$stmt->execute(array($book, $key, $value));	
+			}catch(PDOException $e){
+				fwrite(STDERR,$e->getMessage());
+			}
+            
         }
         // 提交更改
         $dbh_word_index->commit();

+ 23 - 7
app/install/db_insert_palitext_cli.php

@@ -40,7 +40,9 @@ if ($to == 0 || $to >= $fileNums) {
     $to = $fileNums - 1;
 }
 
-PDO_Connect(_PG_DB_PALITEXT_,_DB_USERNAME_,_DB_PASSWORD_);
+$dns = _PG_DB_PALITEXT_;
+$dbh = new PDO($dns, _DB_USERNAME_, _DB_PASSWORD_, array(PDO::ATTR_PERSISTENT => true));
+$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
 
 for ($from=$_from-1; $from < $to; $from++) { 
     # code...
@@ -108,13 +110,20 @@ for ($from=$_from-1; $from < $to; $from++) {
     
     #删除 旧数据
     $query = "DELETE FROM "._PG_TABLE_PALI_TEXT_." WHERE book=?";
-    PDO_Execute($query,array($from+1));
+	$stmt = $dbh->prepare($query);
+	try{
+		$stmt->execute(array($from+1));
+	}catch(PDOException $e){
+		fwrite(STDERR,$e->getMessage());
+		continue;
+	}
+
     
     // 开始一个事务,关闭自动提交
-    $PDO->beginTransaction();
+    $dbh->beginTransaction();
     
     $query = "INSERT INTO "._PG_TABLE_PALI_TEXT_." ( book , paragraph , level , class , toc , text , html , lenght ) VALUES ( ? , ? , ? , ? , ? , ? , ? , ? )";
-    $stmt = $PDO->prepare($query);
+    $stmt = $dbh->prepare($query);
     foreach ($arrInserString as $oneParam) {
         if ($oneParam[3] < 100) {
             $toc = $oneParam[6];
@@ -122,12 +131,19 @@ for ($from=$_from-1; $from < $to; $from++) {
             $toc = "";
         }
         $newData = array($from + 1, $oneParam[2], $oneParam[3], $oneParam[4], $toc, $oneParam[6], $oneParam[5], mb_strlen($oneParam[6], "UTF-8"));
-        $stmt->execute($newData);
+        try{
+			$stmt->execute($newData);
+		}catch(PDOException $e){
+			fwrite(STDERR,$e->getMessage());
+			fwrite(STDERR,implode(",",$newData));
+			break;
+		}
+		
     }
     // 提交更改
-    $PDO->commit();
+    $dbh->commit();
     if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
-        $error = PDO_ErrorInfo();
+        $error = $dbh->errorInfo();
         echo "error - $error[2]".PHP_EOL;
     
         $log = $log . "$from, $FileName, error, $error[2] \r\n";

+ 22 - 13
app/install/db_insert_templet_cli.php

@@ -36,7 +36,10 @@ if (($handle = fopen(__DIR__."/filelist.csv", 'r')) !== false) {
 echo "read file list".PHP_EOL;
 
 
-PDO_Connect(_DB_,_DB_USERNAME_,_DB_PASSWORD_);
+
+$dns = _DB_;
+$dbh = new PDO($dns, _DB_USERNAME_, _DB_PASSWORD_, array(PDO::ATTR_PERSISTENT => true));
+$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
 echo "db Connectd".PHP_EOL;
 
 
@@ -82,23 +85,23 @@ for ($from=$_from; $from <=$_to ; $from++) {
 
 	#删除目标数据库中数据
 	$query = "DELETE FROM "._TABLE_." WHERE book = ?";
-	$stmt = $PDO->prepare($query);
-	if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
-		$error = $PDO->errorInfo();
-		echo "error - $error[2] ";
-		exit;
+	$stmt = $dbh->prepare($query);
+	try{
+		$stmt->execute(array($from));
+	}catch(PDOException $e){
+		fwrite(STDERR,$e->getMessage());
+		continue;
 	}
 
-	$stmt->execute(array($from));
 	echo "delete ".PHP_EOL;
 
 	$row=0;
 	// 开始一个事务,关闭自动提交
-	$PDO->beginTransaction();
+	$dbh->beginTransaction();
 	$query = "INSERT INTO "._TABLE_." ( book , paragraph, wid , word , real , type , gramma , part , style ) VALUES (?,?,?,?,?,?,?,?,?)";
-	$stmt = $PDO->prepare($query);
+	$stmt = $dbh->prepare($query);
 	if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
-		$error = PDO_ErrorInfo();
+		$error = $dbh->errorInfo();
 		echo "error - $error[2]".PHP_EOL;
 
 		$log = "$from, $FileName, error, $error[2] \r\n";
@@ -120,7 +123,13 @@ for ($from=$_from; $from <=$_to ; $from++) {
 						$data[7],
 						$data[10],
 						$data[15]);		
-					$stmt->execute($params);	
+						try{
+							$stmt->execute($params);
+						}catch(PDOException $e){
+							fwrite(STDERR,$e->getMessage());
+							fwrite(STDERR,implode(",",$params));
+							break;
+						}
 				}
 
 				$row++;
@@ -133,9 +142,9 @@ for ($from=$_from; $from <=$_to ; $from++) {
 	}
 
 	// 提交更改
-	$PDO->commit();
+	$dbh->commit();
 	if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
-		$error = PDO_ErrorInfo();
+		$error = $dbh->errorInfo();
 		echo "error - $error[2]".PHP_EOL;
 
 		$log = "$from, $FileName, error, $error[2] \r\n";

+ 16 - 3
app/install/db_insert_word_from_csv_cli.php

@@ -34,7 +34,7 @@ define("_TABLE_", "words");
 global $dbh_word_index;
 $dns = _DB_;
 $dbh_word_index = new PDO($dns, _DB_USERNAME_, _DB_PASSWORD_, array(PDO::ATTR_PERSISTENT => true));
-$dbh_word_index->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
+$dbh_word_index->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
 
 if (($handle = fopen(__DIR__."/filelist.csv", 'r')) !== false) {
     while (($filelist[$fileNums] = fgetcsv($handle, 0, ',')) !== false) {
@@ -50,7 +50,13 @@ for ($from=$_from-1; $from < $_to; $from++) {
     #删除
     $query = "DELETE FROM "._TABLE_." WHERE book = ?";
     $stmt = $dbh_word_index->prepare($query);
-    $stmt->execute(array($from+1));
+	try{
+		$stmt->execute(array($from+1));
+	}catch(PDOException $e){
+		fwrite(STDERR,$e->getMessage());
+		continue;
+	}
+    
 
 
     if (($fpoutput = fopen(_DIR_CSV_PALI_CANON_WORD_ . "/{$from}_words.csv", "r")) !== false) {
@@ -61,7 +67,14 @@ for ($from=$_from-1; $from < $_to; $from++) {
 
         $count = 0;
         while (($data = fgetcsv($fpoutput, 0, ',')) !== false) {
-            $stmt->execute($data);
+			try{
+				$stmt->execute($data);
+			}catch(PDOException $e){
+				fwrite(STDERR,$e->getMessage());
+				fwrite(STDERR,implode(",",$data));
+				break;
+			}
+            
             $count++;
         }
         // 提交更改

+ 14 - 3
app/install/db_insert_wordindex_from_csv_cli.php

@@ -18,12 +18,18 @@ define("_TABLE_", "word_indexs");
 
 $dns = _DB_WORD_INDEX_;
 $dbh_word_index = new PDO($dns, _DB_USERNAME_, _DB_PASSWORD_, array(PDO::ATTR_PERSISTENT => true));
-$dbh_word_index->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
+$dbh_word_index->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
 
 #删除
 $query = "DELETE FROM "._TABLE_." WHERE true";
 $stmt = $dbh_word_index->prepare($query);
-$stmt->execute();
+try{
+	$stmt->execute();
+}catch(PDOException $e){
+	fwrite(STDERR,$e->getMessage());
+	exit;
+}
+
 
     $scan = scandir(_DIR_CSV_PALI_CANON_WORD_INDEX_);
     foreach($scan as $filename) {
@@ -40,7 +46,12 @@ $stmt->execute();
         
                 $count = 0;
                 while (($data = fgetcsv($fpoutput, 0, ',')) !== false) {
-                    $stmt->execute($data);
+					try{
+						$stmt->execute($data);
+					}catch(PDOException $e){
+						fwrite(STDERR,$e->getMessage());
+					}
+                    
                     $count++;
                 }
                 // 提交更改

+ 2 - 1
app/install/db_update_palitext_cli.php

@@ -8,7 +8,7 @@ require_once __DIR__.'/../public/_pdo.php';
 define("_DB_PALITEXT_", _DB_ENGIN_.":host="._DB_HOST_.";port="._DB_PORT_.";dbname="._DB_NAME_.";user="._DB_USERNAME_.";password="._DB_PASSWORD_.";");
 define("_TABLE_","pali_texts");
 
-echo "Insert Pali Text To DB".PHP_EOL;
+echo "Update Pali Text ".PHP_EOL;
 
 if ($argc != 3) {
 	echo "help".PHP_EOL;
@@ -43,6 +43,7 @@ if ($to == 0 || $to >= $fileNums) {
 
 PDO_Connect(_DB_PALITEXT_,_DB_USERNAME_,_DB_PASSWORD_);
 
+
 for ($from=$_from-1; $from < $to; $from++) { 
     echo "doing $from".PHP_EOL;
 

+ 28 - 9
app/install/db_update_toc_cli.php

@@ -39,7 +39,10 @@ if ($to == 0 || $to >= $fileNums) {
     $to = $fileNums - 1;
 }
 
-PDO_Connect(_DB_RES_INDEX_,_DB_USERNAME_,_DB_PASSWORD_);
+
+$dns = _DB_RES_INDEX_;
+$dbh = new PDO($dns, _DB_USERNAME_, _DB_PASSWORD_, array(PDO::ATTR_PERSISTENT => true));
+$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
 
 for ($from=$_from-1; $from < $_to; $from++) { 
     # code...
@@ -92,14 +95,24 @@ for ($from=$_from-1; $from < $_to; $from++) {
     //删除已有标题
     
     $query = "DELETE FROM \""._TABLE_."\" WHERE book = ?  AND  language = ?  ";
-    PDO_Execute($query, array($book,$_lang));
-    
+	try{
+		$stmt = $dbh->prepare($query);
+		$stmt->execute(array($book,$_lang));
+	}catch(PDOException $e){
+		fwrite(STDERR,"error:".$e->getMessage());
+		continue;
+	}
     
     // 开始一个事务,关闭自动提交
-    $PDO->beginTransaction();
+    $dbh->beginTransaction();
     $query = "INSERT INTO \""._TABLE_."\" (book , paragraph, title, title_en , level, type , language , author , share , create_time , update_time  ) VALUES (  ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? )";
-    $stmt = $PDO->prepare($query);
-    if ($_lang == "pali") {
+    try{
+	$stmt = $dbh->prepare($query);
+	}catch(PDOException $e){
+		fwrite(STDERR,"error:".$e->getMessage());
+		break;
+	}
+	if ($_lang == "pali") {
         $type = 1;
     } else {
         $type = 2;
@@ -124,12 +137,18 @@ for ($from=$_from-1; $from < $_to; $from++) {
             mTime(),
             mTime(),
         );
-        $stmt->execute($newData);
+		try{
+			$stmt->execute($newData);
+		}catch(PDOException $e){
+			fwrite(STDERR,"error:".$e->getMessage());
+			fwrite(STDERR,implode(",",$newData));
+			break;
+		}
     }
     // 提交更改
-    $PDO->commit();
+    $dbh->commit();
     if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
-        $error = PDO_ErrorInfo();
+        $error = $dbh->errorInfo();
         echo "error - $error[2] ".PHP_EOL;
         $log = $log . "$from, error, $error[2] \r\n";
     } else {