Performance with php and mysql -


I am developing a site and I have some doubts about the best approach to querying the database. In general, when I load a page, I have to get many data from the database. I'm not sure I'm doing it the best way. So just as an example, I call the following function when the page is provided:

  (...) (a) - & gt; GetAuthorName () / 1db connection - 1db query (b) - & gt; GetAuthorLocation () // 1 DB Connection - 1 DB Query (It is believed that this more information may come to the author ....) (...) (c) count & lt; - countNumberBooks () // 1db connection - 1db query (d) if (calculation == 0) (e) // some more (f) books & lt; - GetBooksByAuthor () / 1db connection - 1db query (g) renderbook ...   
  1. Is it better Is that (A) and (b) the only function for the database in the same function?
  2. What is better (f), count the result and then either (e) or (g), and thus get rid of (c)? Or, is it better to load the need for one thing from the database, bring the data into some kind of structure, and then read it as we present the page?

Thank you!

Some quick answers:

1) Yes, when you can, It is better to get as much data as possible from one line, and it is not divided.

2) It always depends a bit more, if you are always going to use the data you received, then it is better to bring it, and count in php.

3) It is complicated to give a general answer, if you have any type of ORM


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -