Prev | Current Page 163 | Next

Emilian Balanescu and Cristian Darie

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


??? GetAll() is used to execute queries that return more rows of data, such as when requesting
the list of departments.
??? GetRow() is used to execute queries that return a row data.
??? GetOne() returns a single value from the database. We can use this method to call database
stored procedures that return a single value, such as one that returns the subtotal
of a shopping cart.
Exercise: Creating and Using the DatabaseHandler Class
1. Add the database login information at the end of tshirtshop/include/config.php, modifying the
constants??™ values to fit your server??™s configuration. The following code assumes you created the admin user
account as instructed in Chapter 3:
// Database connectivity setup
define('DB_PERSISTENCY', 'true');
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'tshirtshopadmin');
define('DB_PASSWORD', 'tshirtshopadmin');
define('DB_DATABASE', 'tshirtshop');
define('PDO_DSN', 'mysql:host=' . DB_SERVER . ';dbname=' . DB_DATABASE);
2. Create a new file named database_handler.php in the tshirtshop/business folder, and create the
DatabaseHandler class as shown in the following code listing. At this moment, we only included its constructor
(which is private, so the class can??™t be instantiated), and the static GetHandler() method, which
creates a new database connection, saves it into the $_mHandler member, and then returns this object
(find more explanations about the process in the upcoming ???How it Works??? section).


Pages:
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
agencje detektywistyczne Wizzair wózek podnośnikowy ręczny agroturystyka bory tucholskie Curriculum Vitae