dqoqnmb163241 2013-03-22 13:03
浏览 29
已采纳

存储的数据库程序[关闭]

I am working with php and pdo, and some people told me that if I use procedures in the database, my program would greatly improve.

I would like to know what are the improvements that can offer a procedures with respect to the following points:

  • Requests speed.
  • Security aspects. (program and database).
  • Scalability.
  • profitability.
  • When it is convenient to use and when not.
  • Others good and bad points.

Also like to know if possible with PDO parameterized queries calling a procedure.

I appreciate any kind of material on the subject (books, tutorials, code pieces, reviews).

  • 写回答

1条回答 默认 最新

  • duanji9311 2013-03-22 13:27
    关注

    Good question when it comes to decide which part of the program to be executed where. I had a similar question when I was coding an application using Classic ASP and MS SQL Server.

    Before I answer your query, I would like to note that a web application has minimum three tiers:

    • the presentation tier, e.g., the client's web browser
    • an application tier - where your PHP or JSP or ASP servers run
    • and the database tier- where the data resides.

    It is common sense that whatever data validation that is possible to be carried out at the presentation tier, we put it there. E.g., checking if a certain form field is empty.

    It is interesting when the application has to be developed at the other two tiers - the application and database tiers. Many bad programmers code in such a way that there are many round trips between the web server and the DB server for very little things. We should consider coding stored procedures in the database at these times.

    About the points you have mentioned, I would like to answer:

    • Requests speed.

      The requests made to your web server are processed faster as there are less round-trips between the web server and the database server. The difference is particularly notable when your application grows very complex and data grows too large, in terms of multiple hundred TBs. The processing load is transferred from your web server to your DB server, hence your web server is more available for your client requests.

    • Security aspects. (program and database).

      The security offered to your program is now at two levels - at the web server level and database level. You can put restrictions on the communications between these two to make sure your program doesn't collapse and data is intact.

    • Scalability.

      The web server code and database server code is now at two different tiers. Both the tiers can scale independently as per requirements. Read here for exactly what is meant by scalability.

    • Profitability.

      I don't know how to answer this, but a thought just came across my mind: If you're paying a database server and letting it sit idle while the web server is overloaded, what's the point? If I'm paying for a database server, I'd make full use of it by giving it some of the processing load that my web server has.

    • When it is convenient to use and when not.

      It is most convenient to use when there are too many round-trips between the web and database server. I might be mentioning this again and again but this issue turns out to be a big headache.

      When it is not convenient? Well, in simple cases where a single SQL statement does everything necessary.

    • Others good and bad points.

      • You must be sure about the communication between these two tiers - what is passed and what is received. Keep everything well documented as any mistake would hamper both the tiers.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?