sent_query.php 1023 B

1234567891011121314151617181920212223242526272829303132333435
  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. $sent = $_POST["sent"];
  9. $filter = $_POST["filter"];
  10. $sentList = json_decode($sent);
  11. $output = array();
  12. $dns = "sqlite:"._FILE_DB_SENTENCE_;
  13. $dbh = new PDO($dns, "", "",array(PDO::ATTR_PERSISTENT=>true));
  14. $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
  15. /* 开始一个事务,关闭自动提交 */
  16. $query="SELECT * FROM sentence WHERE (book = ? AND paragraph = ? AND begin = ? AND end = ? AND text <> '' ) order by modify_time DESC limit 0,10";
  17. $stmt = $dbh->prepare($query);
  18. foreach ($sentList as $key => $value) {
  19. # code...
  20. $stmt->execute(array($value->book,$value->para,$value->start,$value->end));
  21. $Fetch = $stmt->fetchAll(PDO::FETCH_ASSOC);
  22. $sent = array();
  23. $sent["info"]=$value;
  24. $sent["data"]=$Fetch;
  25. $sent["count"]=count($Fetch);//句子个数
  26. $output[] = $sent;
  27. }
  28. echo json_encode($output, JSON_UNESCAPED_UNICODE);
  29. ?>