dousheng3364 2015-07-05 12:50
浏览 70

mysql查询安全限制

I'm quite inexperienced in this area so it may seem like a dumb question, but please bear with me.

Got a mysql DB and a query, via PHP PDO that look like this:

SELECT p.*, group_concat( distinct c.color) as color, b.breeder_puppy_thumb , b.breeder_name
FROM puppy_list p 
JOIN puppies_join_colors pjc ON p.ID = pjc.puppy_ID 
JOIN puppy_colors c ON c.ID = pjc.color_ID 
JOIN breeder_list b ON b.ID = p.puppy_breeder_id 
WHERE p.puppy_breed = :breedName
GROUP BY p.ID
ORDER BY p.price DESC

The ORDER BY clause can vary (can be ordered by a different field).

I send this query via AJAX to a PHP file that sends it to the DB server - so round trip, 4 hops.

In my website, there is pagination and it's done on the fly, all data is in memory in the form a big JSON object - and the processing is done on this JSON object, in the front end framework (angularJS based - pagination too), without querying the DB again.

My first question is: given a query like this one, with the rows returned being in the thousands (tens of thousands) what's a safe limit to put in place on a single query? How many rows should i return so that i won't overkill the client?

My second question is: should i move part of the processing away from angular to the back-end framework or go with it like this?

If i didn't formulate the question well enough, please let me know and i'll try and address that.

  • 写回答

1条回答 默认 最新

  • dsdtszi0520538 2015-07-06 18:11
    关注

    @Radu Andrei, Drew Pierce has some valid points.

    On your first question => you can do what Facebook is currently using, "Infinity Scroll". It is a fancy way of displaying pagination. Loads more results when the user reaches the bottom or displays a "load more" button. See an example here: http://www.w3bees.com/2013/09/jquery-infinite-scroll-with-php-mysql.html

    On your second question => a good programming solution is to have both back-end and front end working properly in case a user disables java-script. However, nowadays js is enabled by default. I would say keep the JS front end and have the back-end programmed as well. You never know what users disable. Always keep mobile devices in mind while doing this, they may not appreciate 1000 items per page especially nowadays, almost all our browsing is on mobile devices.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作