2
0

sent_query.php 1.7 KB

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