The stored procedure executes the SELECT statement and returns the results.
CHAPTER 4 ?– CREATING THE PRODUCT CATALOG: PART 1 84
Adding Logic to the Site
The business tier (or middle tier) is said to be the brains of the application, because it manages
the application??™s business logic. However, for simple tasks such as getting a list of departments
from the data tier, the business tier doesn??™t have much logic to implement. It just requests the
data from the database and passes it along. Usually, there will be a presentation tier object
that will request this data, but it could be another business tier method that needs the data to
implement some more complex functionality.
In this chapter, we??™re building the foundation of the business tier, which includes the functionality
to open and close database connections, store data logic as MySQL stored procedures,
and access these stored procedures from PHP.
For the business tier of the departments list, you??™ll implement two classes:
??? DatabaseHandler will store the common functionality that you??™ll reuse whenever you
need to access the database. Having this kind of generic functionality packed in
a separate class saves keystrokes and avoids bugs in the long run.
??? Catalog contains product-catalog-specific functionality, such as the GetDepartments()
method that will retrieve the list of departments from the database.
Pages:
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164