getConnection(); if (!$pdo) { throw new Exception('Connessione al database non valida'); } // Query per selezionare i template dalla tabella excel_templates $stmt = $pdo->query("SELECT * FROM excel_templates ORDER BY created_at DESC"); $templates = $stmt->fetchAll(PDO::FETCH_ASSOC); echo json_encode(['success' => true, 'data' => $templates]); } catch (PDOException $e) { http_response_code(500); echo json_encode(['success' => false, 'message' => 'Errore PDO: ' . $e->getMessage()]); } catch (Exception $e) { http_response_code(500); echo json_encode(['success' => false, 'message' => 'Errore interno: ' . $e->getMessage()]); } finally { ob_end_flush(); } error_log('Errore in load_templates.php: ' . (isset($e) ? $e->getMessage() : 'Nessun errore catturato'));