getDownloads.php 1.1 KB

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