Prev | Current Page 299 | Next

Emilian Balanescu and Cristian Darie

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

We??™ll now add the business tier code that accesses the stored procedures created earlier. Add the following
code to the Catalog class in business/catalog.php:
// Retrieves department name
public static function GetDepartmentName($departmentId)
{
// Build SQL query
$sql = 'CALL catalog_get_department_name(:department_id)';
CHAPTER 7 ?–  SEARCH ENGINE OPTIMIZATION 199
// Build the parameters array
$params = array (':department_id' => $departmentId);
// Execute the query and return the results
return DatabaseHandler::GetOne($sql, $params);
}
// Retrieves category name
public static function GetCategoryName($categoryId)
{
// Build SQL query
$sql = 'CALL catalog_get_category_name(:category_id)';
// Build the parameters array
$params = array (':category_id' => $categoryId);
// Execute the query and return the results
return DatabaseHandler::GetOne($sql, $params);
}
// Retrieves product name
public static function GetProductName($productId)
{
// Build SQL query
$sql = 'CALL catalog_get_product_name(:product_id)';
// Build the parameters array
$params = array (':product_id' => $productId);
// Execute the query and return the results
return DatabaseHandler::GetOne($sql, $params);
}
3. Open presentation/link.php, and modify its code like this:
public static function ToDepartment($departmentId, $page = 1)
{
$link = self::CleanUrlText(Catalog::GetDepartmentName($departmentId)) .


Pages:
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311