sent_query.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. /*
  3. get user sentence from db
  4. */
  5. require_once "../path.php";
  6. require_once "../public/_pdo.php";
  7. require_once "../public/function.php";
  8. require_once "../ucenter/function.php";
  9. $sent = $_POST["sent"];
  10. $filter = $_POST["filter"];
  11. $sentList = json_decode($sent);
  12. $output = array();
  13. $dns = "sqlite:"._FILE_DB_SENTENCE_;
  14. $dbh = new PDO($dns, "", "",array(PDO::ATTR_PERSISTENT=>true));
  15. $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
  16. /* 开始一个事务,关闭自动提交 */
  17. $query="SELECT * FROM sentence WHERE (book = ? AND paragraph = ? AND begin = ? AND end = ? AND strlen > 0 ) order by modify_time DESC limit 0,10";
  18. $stmt = $dbh->prepare($query);
  19. foreach ($sentList as $key => $value) {
  20. # code...
  21. $stmt->execute(array($value->book,$value->para,$value->start,$value->end));
  22. $Fetch = $stmt->fetchAll(PDO::FETCH_ASSOC);
  23. for($i=0 ; $i<count($Fetch) ; $i++) {
  24. $Fetch[$i]["nickname"] = ucenter_getA($Fetch[$i]["editor"]);
  25. }
  26. $sent = array();
  27. $sent["info"]=$value;
  28. $sent["data"]=$Fetch;
  29. $sent["count"]=count($Fetch);//句子个数
  30. $output[] = $sent;
  31. }
  32. echo json_encode($output, JSON_UNESCAPED_UNICODE);
  33. ?>