Note that before the error is generated, we also close the database connection to ensure that we??™re not leaving
any database resources occupied by the script.
By default, if you don??™t specify to trigger_error() the kind of error to generate, an E_USER_NOTICE message
is generated, which doesn??™t interfere with the normal execution of the request (the error is eventually logged, but
execution continues normally afterward).
The functionality in the DatabaseHandler class is meant to be used in the other business tier classes, such as
Catalog. At this moment, Catalog contains a single method: GetDepartments().
// Business tier class for reading product catalog information
class Catalog
{
// Retrieves all departments
public static function GetDepartments()
{
// Build SQL query
$sql = 'CALL catalog_get_departments_list()';
// Execute the query and return the results
return DatabaseHandler::GetAll($sql);
}
}
CHAPTER 4 ?– CREATING THE PRODUCT CATALOG: PART 1 98
Because it relies on the functionality you??™ve already included in the DatabaseHandler class and in the database
functions in place, the code in Catalog is very simple and straightforward. The GetDepartments() method will
be called from the presentation tier, which will display the returned data to the visitor. It starts by building the SQL
query, and then calling the appropriate DatabaseHandler method to execute the query.
Pages:
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182