db = $db; } /** * Get all services. * * @return array */ public function getAllServices(): array { try { Logger::info("[DEBUG] Fetching all services"); $stmt = $this->db->query("SELECT * FROM services"); $services = $stmt->fetchAll(\PDO::FETCH_ASSOC); Logger::info("[DEBUG] Retrieved services: " . json_encode($services)); return $services; } catch (\Exception $e) { Logger::error("[ERROR] Failed to fetch services: " . $e->getMessage()); ErrorHandler::exception($e); return []; } } /** * Get a service by ID. * * @param int $id * @return array|null */ public function getServiceById(int $id): ?array { try { Logger::info("[DEBUG] Fetching service with ID: $id"); $stmt = $this->db->prepare("SELECT * FROM services WHERE id = :id"); $stmt->bindParam(':id', $id, \PDO::PARAM_INT); $stmt->execute(); $service = $stmt->fetch(\PDO::FETCH_ASSOC); Logger::info("[DEBUG] Service data retrieved: " . json_encode($service)); return $service ?: null; } catch (\Exception $e) { Logger::error("[ERROR] Failed to fetch service with ID $id: " . $e->getMessage()); ErrorHandler::exception($e); return null; } } /** * Add a new service to the database. * * @param array $serviceData * @return bool */ public function addService(array $serviceData): bool { try { Logger::info("[DEBUG] Adding new service: " . json_encode($serviceData)); $stmt = $this->db->prepare( "INSERT INTO services (name, description, price) VALUES (:name, :description, :price)" ); $stmt->bindParam(':name', $serviceData['name']); $stmt->bindParam(':description', $serviceData['description']); $stmt->bindParam(':price', $serviceData['price']); $stmt->execute(); Logger::info("[DEBUG] Service successfully added."); return true; } catch (\Exception $e) { Logger::error("[ERROR] Failed to add service: " . $e->getMessage()); ErrorHandler::exception($e); return false; } } }