pali_sim_sent.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. require_once "../path.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_, "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 sent_sim 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. $this->redis->hSet('pali://sim/id',$id, $output);
  24. return $simList;
  25. }
  26. else{
  27. return false;
  28. }
  29. }
  30. public function getInfo($id)
  31. {
  32. $query = "SELECT book,paragraph, begin,end from pali_sent where id = ? ";
  33. $stmt = $this->dbh->prepare($query);
  34. $stmt->execute(array($id));
  35. $result = $stmt->fetch(PDO::FETCH_ASSOC);
  36. if ($result) {
  37. return $result;
  38. }
  39. return false;
  40. }
  41. }
  42. ?>