sent_query.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /*
  3. get user sentence from db
  4. */
  5. require_once "../config.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 = _FILE_DB_SENTENCE_;
  14. $dbh = new PDO($dns, _DB_USERNAME_, _DB_PASSWORD_, array(PDO::ATTR_PERSISTENT => true));
  15. $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
  16. /* 开始一个事务,关闭自动提交 */
  17. $query = "SELECT uid as id,
  18. parent_uid as parent,
  19. block_uid as block_id,
  20. channel_uid as channal,
  21. book_id as book,
  22. paragraph,
  23. word_start as begin,
  24. word_end as end,
  25. author,
  26. editor_uid as editor,
  27. content as text,
  28. language,
  29. version as ver,
  30. status,
  31. strlen,
  32. modify_time FROM "._TABLE_SENTENCE_." WHERE (book_id = ? AND paragraph = ? AND word_start = ? AND word_end = ? AND strlen > 0 ) order by modify_time DESC limit 10";
  33. $stmt = $dbh->prepare($query);
  34. foreach ($sentList as $key => $value) {
  35. # code...
  36. $stmt->execute(array($value->book, $value->para, $value->start, $value->end));
  37. $Fetch = $stmt->fetchAll(PDO::FETCH_ASSOC);
  38. for ($i = 0; $i < count($Fetch); $i++) {
  39. $Fetch[$i]["nickname"] = ucenter_getA($Fetch[$i]["editor"]);
  40. }
  41. $sent = array();
  42. $sent["info"] = $value;
  43. $sent["data"] = $Fetch;
  44. $sent["count"] = count($Fetch); //句子个数
  45. $output[] = $sent;
  46. }
  47. echo json_encode($output, JSON_UNESCAPED_UNICODE);