2
0

pali_sent.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. require_once "../path.php";
  3. require_once "../db/table.php";
  4. class PaliSentence extends Table
  5. {
  6. function __construct($redis=false) {
  7. parent::__construct(_FILE_DB_PALI_SENTENCE_, "pali_sent", "", "",$redis);
  8. }
  9. public function getId($book,$para,$start,$end)
  10. {
  11. if (isset($book) && isset($para))
  12. {
  13. if($this->redis!==false){
  14. $result = $this->redis->hGet('pali://sent/' . $book . "_" . $para . "_" . $start . "_" . $end, "id");
  15. if($result!==FALSE){
  16. return $result;
  17. }
  18. }
  19. $id=0;
  20. $query = "SELECT id from pali_sent where book = ? and paragraph = ? and begin=? and end=?";
  21. $stmt = $this->dbh->prepare($query);
  22. $stmt->execute(array($book,$para,$start,$end));
  23. $result = $stmt->fetch(PDO::FETCH_ASSOC);
  24. if ($result) {
  25. $id= $result["id"];
  26. }
  27. $output = $this->redis->hSet('pali://sent/' . $book . "_" . $para . "_" . $start . "_" . $end, "id",$id);
  28. return $id;
  29. } else {
  30. return 0;
  31. }
  32. }
  33. public function getInfo($id)
  34. {
  35. $query = "SELECT book,paragraph, begin,end from pali_sent where id = ? ";
  36. $stmt = $this->dbh->prepare($query);
  37. $stmt->execute(array($id));
  38. $result = $stmt->fetch(PDO::FETCH_ASSOC);
  39. if ($result) {
  40. return $result;
  41. }
  42. return false;
  43. }
  44. }
  45. ?>