load(); } catch (Exception $e) { file_put_contents(__DIR__ . '/error_log.txt', date('Y-m-d H:i:s') . ' - Errore caricamento .env: ' . $e->getMessage() . PHP_EOL, FILE_APPEND); echo json_encode(['success' => false, 'message' => 'Errore caricamento configurazione: ' . $e->getMessage()]); exit(1); } // Recupera le variabili d'ambiente $dbHost = $_ENV['DB_HOST']; $dbName = $_ENV['DB_DATABASE']; $dbUser = $_ENV['DB_USERNAME']; $dbPass = $_ENV['DB_PASSWORD']; $dbPrefix = $_ENV['DB_PREFIX']; // Debug: Log database connection details (excluding password) file_put_contents(__DIR__ . '/debug_log.txt', date('Y-m-d H:i:s') . " - DB Connection: host=$dbHost, dbname=$dbName, user=$dbUser, prefix=$dbPrefix" . PHP_EOL, FILE_APPEND); // Connessione al database MySQL try { $pdo = new PDO("mysql:host=$dbHost;dbname=$dbName;charset=utf8mb4", $dbUser, $dbPass); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { file_put_contents(__DIR__ . '/error_log.txt', date('Y-m-d H:i:s') . ' - Errore connessione DB: ' . $e->getMessage() . PHP_EOL, FILE_APPEND); echo json_encode(['success' => false, 'message' => 'Errore connessione al database: ' . $e->getMessage()]); exit(1); } try { // Query per recuperare i valori distinti di MacroMatrice, escludendo quelli che iniziano con '*' e ordinandoli $query = "SELECT DISTINCT MacroMatrice FROM {$dbPrefix}matrici WHERE MacroMatrice IS NOT NULL AND MacroMatrice NOT LIKE '*%' ORDER BY MacroMatrice ASC"; $stmt = $pdo->prepare($query); $stmt->execute(); $macroMatrici = $stmt->fetchAll(PDO::FETCH_COLUMN); // Debug: Log del numero di MacroMatrice recuperate file_put_contents(__DIR__ . '/debug_log.txt', date('Y-m-d H:i:s') . ' - Retrieved ' . count($macroMatrici) . ' MacroMatrice from database' . PHP_EOL, FILE_APPEND); // Restituisci risposta JSON echo json_encode(['success' => true, 'value' => $macroMatrici]); } catch (PDOException $e) { // Log errore e restituisci risposta di errore file_put_contents(__DIR__ . '/error_log.txt', date('Y-m-d H:i:s') . ' - Errore nel recupero delle MacroMatrice: ' . $e->getMessage() . PHP_EOL, FILE_APPEND); echo json_encode(['success' => false, 'message' => 'Errore nel recupero delle MacroMatrice: ' . $e->getMessage()]); exit(1); }