updatadict.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <html>
  2. <body>
  3. <?php
  4. function inputWordIsEmpty($inWord){
  5. if(strcmp($inWord->org,'?')==0 && strcmp($inWord->mean,'?')==0 && strcmp($inWord->case,'?')==0 ){
  6. return true;
  7. }
  8. return false;
  9. }
  10. ?>
  11. <?php
  12. include "./_pdo.php";
  13. $xmlFileName = $_GET["filename"];
  14. $xml = simplexml_load_file("books/".$xmlFileName);
  15. //open database
  16. $db_file = "dict/tpdict.db";
  17. PDO_Connect("sqlite:$db_file");
  18. //get word list from xml documnt and updata database
  19. $wordsSutta = $xml->xpath('//word');
  20. echo "word number:".count($wordsSutta)."<br>";
  21. $countInsert=0;
  22. foreach($wordsSutta as $ws){
  23. $strPali = strtolower($ws->pali);
  24. $strPaliInEn = $strPali;
  25. $strOrg = $ws->org;
  26. $strMean = $ws->mean;
  27. $strGrama = $ws->case;
  28. if(inputWordIsEmpty($ws) ){
  29. continue;
  30. }
  31. $query = "select count(*) as rownum from tptdict where \"word\"='".$ws->pali."' AND \"org\"='".$ws->org."' AND \"mean\"='".$ws->mean."' AND \"gramma\"='".$ws->case."'";
  32. $Fetch = PDO_FetchAll($query);
  33. $FetchNum = $Fetch[0]["rownum"];
  34. if($FetchNum==0)
  35. {
  36. $query = "INSERT INTO tptdict ('id','worden','word', 'org', 'mean', 'gramma') VALUES (null,'".$ws->pali."','".$ws->pali."','".$ws->org."','".$ws->mean."','".$ws->case."')";
  37. $stmt = @PDO_Execute($query);
  38. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  39. $error = PDO_ErrorInfo();
  40. print_r($error[2]);
  41. //break;
  42. }
  43. $countInsert++;
  44. echo "insert-".$ws->pali."<br>";
  45. }
  46. }
  47. echo "<b>insert:".$countInsert." words</b><br>";
  48. ?>
  49. </body>
  50. </html>