Challenge 2 — Solution Task: Write a queueJob(PDO $pdo, string $type, array $payload) function that inserts a new pending job with a JSON-encoded payload, generalising the chapter's queueEmail() to handle any job type. Then show how it would be called for two different job types: 'send_email' and 'resize_image'. prepare("INSERT INTO jobs (type, payload, status) VALUES (:type, :payload, 'pending')"); $stmt->execute([ 'type' => $type, 'payload' => json_encode($payload) ]); } // Called for a "send_email" job: queueJob($pdo, 'send_email', [ 'to' => 'sam@example.com', 'subject' => 'Welcome!' ]); // Called for a "resize_image" job: queueJob($pdo, 'resize_image', [ 'source_path' => '/uploads/photo_original.jpg', 'target_width' => 800, 'target_height' => 600 ]); ?> Output: (No direct output — both calls insert a new row into the jobs table, each with its own $type value and a JSON-encoded $payload matching that job's own specific data needs.) Notes: - queueJob() generalises the chapter's own queueEmail() by accepting $type as a genuine parameter rather than hardcoding 'send_email' in the SQL, and by accepting a plain $payload array rather than separate $to/$subject parameters - letting it handle any job's own arbitrarily-shaped data. - Both example calls pass a completely different payload shape (to/subject for email, source_path/target_width/target_height for image resizing) - exactly demonstrating why payload is stored as flexible JSON text rather than fixed database columns, per Challenge 1's own reasoning. - The prepared statement with named placeholders (:type, :payload) reuses the exact SQL-injection-safe pattern from Intermediate Chapter 4, applied here to job-queue data rather than user-facing form data.