Prev | Current Page 154 | Next

Emilian Balanescu and Cristian Darie

"Beginning PHP and MySQL E-Commerce: From Novice to Professional, Second Edition"


3. Close the database connection immediately after executing the command.
CHAPTER 4 ?–  CREATING THE PRODUCT CATALOG: PART 1 85
This method has the advantage that you don??™t keep database connections for a long time
(which is good because database connections consume server resources), and it is also encouraged
for servers that don??™t allow many simultaneous database connections. The disadvantage
is the overhead implied by opening and closing the database connection every time, which
can be partially reduced by using persistent connections.
?– Note ???Persistent connections??? refers to a technology that attempts to improve the efficiency of opening
and closing database connections with no impact on functionality. You can learn more about this technology
at http://www.php.net/manual/en/features.persistent-connections.php.
The alternative solution, and the one you??™ll use when implementing TShirtShop, is like this:
1. Open a connection to the database the first time you need to access the database during
a request.
2. Execute all database stored procedures (or SQL queries) through that connection
without closing it. Here, you also need to handle any possible errors.
3. Close the database connection when the client request finishes processing.
Using this method, all database operations that happen for a single client request (which
happens each time a user visits a new page of our site) will go through a single database connection,
avoiding opening and closing the connection each time you need something from
the database.


Pages:
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
ciekawe zdania obrazki Party Poker noclegi w górach słownik