??? The query will likely execute faster with prepared statements, because the database
server can reuse the access plan it builds for a prepared statement.
To be able to reuse more of the database-handling code and to have a centralized errorhandling
mechanism for the database code, we won??™t be using the PDO methods directly from
the business tier of our application. Instead, we??™ll wrap the PDO functionality into a class named
DatabaseHandler, and we??™ll use this class from the other classes of the business tier.
CHAPTER 4 ?– CREATING THE PRODUCT CATALOG: PART 1 90
Writing the Business Tier Code
OK, let??™s write some code! You??™ll start by writing the DatabaseHandler class, which will be
a support class that contains generic functionality needed in the other business tier methods.
Next, you??™ll create a business tier class named Catalog, which uses the DatabaseHandler
class to provide the functionality required by the presentation tier. The Catalog class will contain
methods such as GetDepartments() (which will be used to generate the list of departments),
GetCategories(), and so on. The only method we??™ll need to add to the Catalog class in this
chapter is GetDepartments().
Although in this chapter we won??™t need all this functionality, we??™ll write the complete code
of the DatabaseHandler class. DatabaseHandler will have the following methods:
??? Execute() executes a stored procedure that doesn??™t return records from the database,
such as INSERT, DELETE, or UPDATE statements.
Pages:
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174