如何在完整脚本中对代码中的查询进行计数

My question here is seems subjective, but it's too important to me to know the answer to have a good future plans while coding.

  1. If I have a script with 100 files and each file has it's own queries, and some queries are in the included classes. How can I count time that took the script to get the information from the database in a specific file.? Knowing this will give me a good values to redesign some files structure.

  2. Is there any specific max number of queries in order to keep a program or a script efficient?

  1. For this kind of profiling, I can recommend you xhprof: https://github.com/facebook/xhprof
  2. It heavily depends on the complexity of the queries, size of the database and resources of the server. If you proceed to optimize your scripts, beside reducing the number of queries, reusing MySQL connections will also definately help. (No reconnect overhead each time, etc.)