You need to include the newly created database_handler.php in index.php to make the class available
for the application. To do this, add the highlighted code to the index.php file:
// Include utility files
require_once 'include/config.php';
require_once BUSINESS_DIR . 'error_handler.php';
// Sets the error handler
ErrorHandler::SetHandler();
// Load the application page template
require_once PRESENTATION_DIR . 'application.php';
// Load the database handler
require_once BUSINESS_DIR . 'database_handler.php';
10. At the end of index.php, add the highlighted code that closes the database connection:
// Load Smarty template file
$application = new Application();
// Display the page
$application->display('store_front.tpl');
// Close database connection
DatabaseHandler::Close();
?>
How It Works: The Business Tier Code
After adding the database connection data to include/config.php, you created the DatabaseHandler class.
This class contains a number of wrapper methods that access PDO methods and provide the functionality needed
for the rest of the business tier methods.
CHAPTER 4 ?– CREATING THE PRODUCT CATALOG: PART 1 96
The DatabaseHandler class has a private constructor, meaning that it can??™t be instantiated; you can??™t create
DatabaseHandler objects, but you can execute the static methodsfor the class. Static class members and
methods, as opposed to instance members and methods, are owned not by a particular instance of the class but
by the class as a whole.
Pages:
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179