pali_sim_sent.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. require_once "../config.php";
  3. require_once "../db/table.php";
  4. class PaliSimSentence extends Table
  5. {
  6. function __construct($redis=false) {
  7. parent::__construct(_FILE_DB_PALI_SENTENCE_SIM_, _TABLE_SENT_SIM_, "", "",$redis);
  8. }
  9. public function getSimById($id)
  10. {
  11. if($this->redis!==false){
  12. $result = $this->redis->hGet('pali://sim/id' , $id );
  13. if($result!==FALSE){
  14. return json_decode($result,true);
  15. }
  16. }
  17. $query = "SELECT sent2 as id FROM ".$this->table." WHERE sent1 = ? ";
  18. $stmt = $this->dbh->prepare($query);
  19. if($stmt){
  20. $stmt->execute(array($id));
  21. $simList = $stmt->fetchAll(PDO::FETCH_ASSOC);
  22. $output = json_encode($simList, JSON_UNESCAPED_UNICODE);
  23. if($this->redis){
  24. $this->redis->hSet('pali://sim/id',$id, $output);
  25. }
  26. return $simList;
  27. }
  28. else{
  29. return false;
  30. }
  31. }
  32. public function getInfo($id)
  33. {
  34. $query = "SELECT book,paragraph, begin,end from pali_sent where id = ? ";
  35. $stmt = $this->dbh->prepare($query);
  36. $stmt->execute(array($id));
  37. $result = $stmt->fetch(PDO::FETCH_ASSOC);
  38. if ($result) {
  39. return $result;
  40. }
  41. return false;
  42. }
  43. }
  44. ?>