prepare($sql); $sth->execute([':id' => $id, ':cid' => $company_id]); $row = $sth->fetch(PDO::FETCH_ASSOC); if (!$row) { exit(json_encode(['success' => 0, 'message' => 'Not found'])); } $row['items'] = json_decode($row['items'] ?? '[]', true); $answer['output'] = $row; } else { // List $sql = "SELECT q.*, c.contact_name FROM ac_quotation q LEFT JOIN md_contact c ON c.id = q.contact_id WHERE q.company_id = :cid ORDER BY q.id DESC"; $sth = $pdo2->prepare($sql); $sth->execute([':cid' => $company_id]); $answer['output'] = $sth->fetchAll(PDO::FETCH_ASSOC); } $answer['success'] = 1; exit(json_encode($answer));