get_split_data.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. require_once '../config.php';
  3. require_once '../redis/function.php';
  4. require_once '../dict/function.php';
  5. $output=json_encode(array(), JSON_UNESCAPED_UNICODE);
  6. if(isset($_GET["word"])){
  7. $inputWord = $_GET["word"];
  8. }
  9. else{
  10. echo json_encode($output, JSON_UNESCAPED_UNICODE);
  11. exit;
  12. }
  13. $redis = redis_connect();
  14. if($redis!==false){
  15. #如果没有查巴缅替换拆分
  16. if($redis->hExists("dict://comp",$inputWord)===TRUE){
  17. $output = $redis->hGet("dict://comp",$inputWord) ;
  18. if(empty($output)){
  19. echo json_encode(array(), JSON_UNESCAPED_UNICODE);
  20. }
  21. else{
  22. echo $output;
  23. }
  24. }
  25. else{
  26. echo json_encode(array(), JSON_UNESCAPED_UNICODE);
  27. }
  28. }
  29. else{
  30. $dbh = new PDO(_DICT_DB_COMP_, "", "", array(PDO::ATTR_PERSISTENT => true));
  31. $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
  32. $query = "SELECT parts from "._TABLE_DICT_COMP_." where pali =?";
  33. $stmt = $dbh->prepare($query);
  34. $stmt->execute(array($inputWord));
  35. $fComp = $stmt->fetchAll(PDO::FETCH_ASSOC);
  36. $output = json_encode($fComp, JSON_UNESCAPED_UNICODE);
  37. echo $output;
  38. }
  39. ?>