getDownloadItems.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. include('../conn_mysqli.php');
  3. include('../phpMode/rcodeMap.php');
  4. // 目前基于设备管理的下载项
  5. $page = isset($_POST['page']) ? max(1, min(10, intval($_POST['page']))) : 1;
  6. // 设置 $limit 的默认值为20,并限定取值范围在1-100之间
  7. $limit = isset($_POST['limit']) ? max(1, min(100, intval($_POST['limit']))) : 20;
  8. $offset = ($page - 1) * $limit;
  9. $id = $_POST['id'];
  10. header('Content-Type:text/json;charset=utf-8;');
  11. $resObj = array(
  12. 'rcode' => Rcode_OK,
  13. 'data' => "",
  14. 'msg' => 'ok'
  15. );
  16. if(!isset($_POST['id'])){
  17. $resObj['rcode'] = Rcode_NotParam;
  18. $resObj['data'] = "";
  19. $resObj['msg'] = "id is must set";
  20. echo json_encode($resObj);
  21. exit;
  22. }
  23. try {
  24. set_time_limit(50);
  25. $conn = createConn();
  26. $sql = "";
  27. $stmt = null;
  28. // 获取id为
  29. $sql = 'select * from mysql85931094_db.hfy_downloads where p_id = ? order by id desc limit ?,?';
  30. $stmt = mysqli_prepare($conn, $sql);
  31. mysqli_stmt_bind_param($stmt, "sdd",$id, $offset, $limit);
  32. mysqli_stmt_execute($stmt);
  33. $res = mysqli_stmt_get_result($stmt);
  34. while ($row = mysqli_fetch_assoc($res)) {
  35. $rs[] = $row;
  36. }
  37. mysqli_close($conn);
  38. $resObj['data'] = $rs;
  39. echo json_encode($resObj);
  40. }catch(Exception $e)
  41. {
  42. // echo 'Message: ' .$e->getMessage();
  43. $resObj['rcode'] = Rcode_ServerError;
  44. $resObj['msg'] = 'server error';
  45. echo json_encode($resObj);
  46. }