2
0

get_sim.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. /*
  3. get user sentence from db
  4. */
  5. require_once "../config.php";
  6. require_once "../public/_pdo.php";
  7. require_once "../public/function.php";
  8. //获取相似句子列表
  9. if (isset($_POST["sent_id"])) {
  10. $dns = _FILE_DB_PALI_SENTENCE_SIM_;
  11. $dbh_sim = new PDO($dns, _DB_USERNAME_, _DB_PASSWORD_, array(PDO::ATTR_PERSISTENT => true));
  12. $dbh_sim->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
  13. $query = "SELECT sent2 FROM "._TABLE_SENT_SIM_." WHERE sent1 = ? limit 10";
  14. $stmt = $dbh_sim->prepare($query);
  15. $stmt->execute(array($_POST["sent_id"]));
  16. $simList = $stmt->fetchAll(PDO::FETCH_ASSOC);
  17. } else {
  18. $sim = $_POST["sim"];
  19. $simList = json_decode($sim);
  20. }
  21. $output = array();
  22. $dns = _FILE_DB_PALI_SENTENCE_;
  23. $dbh = new PDO($dns, _DB_USERNAME_, _DB_PASSWORD_, array(PDO::ATTR_PERSISTENT => true));
  24. $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
  25. $query = "SELECT book,paragraph,word_begin as begin ,word_end as end,text ,html FROM "._TABLE_PALI_SENT_." WHERE id = ? ";
  26. $stmt = $dbh->prepare($query);
  27. $count = 0;
  28. foreach ($simList as $value) {
  29. # code...
  30. $stmt->execute(array($value["sent2"]));
  31. $Fetch = $stmt->fetch(PDO::FETCH_ASSOC);
  32. if ($Fetch) {
  33. $sent = $Fetch;
  34. $sent["path"] = _get_para_path($Fetch["book"], $Fetch["paragraph"]);
  35. $output[] = $sent;
  36. }
  37. }
  38. echo json_encode($output, JSON_UNESCAPED_UNICODE);