PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, ]); // --- Download --- $url = 'https://celestrak.org/pub/satcat.csv'; echo "Lade satcat.csv von CelesTrak...\n"; $content = @file_get_contents($url); if ($content === false) { exit("Download fehlgeschlagen. Netzwerkverbindung prüfen.\n"); } echo 'Download OK (' . number_format(strlen($content)) . " Bytes).\n"; // --- CSV einlesen --- $lines = explode("\n", str_replace("\r\n", "\n", $content)); if (count($lines) < 2) { exit("CSV leer oder ungültig.\n"); } // Header-Zeile parsen $header = str_getcsv(array_shift($lines)); $header = array_map('trim', $header); $idxNorad = array_search('NORAD_CAT_ID', $header, true); $idxRcs = array_search('RCS', $header, true); if ($idxNorad === false || $idxRcs === false) { exit("Erwartete Spalten NORAD_CAT_ID / RCS nicht gefunden. Header: " . implode(', ', $header) . "\n"); } // --- Update vorbereiten --- $stmt = $pdo->prepare(" UPDATE `sat_satellites` SET `rcs` = :rcs WHERE `norad_cat_id` = :norad "); $updated = 0; $skipped = 0; // nicht in DB $noRcs = 0; // RCS leer in satcat $total = 0; foreach ($lines as $line) { $line = trim($line); if ($line === '') { continue; } $cols = str_getcsv($line); $norad = isset($cols[$idxNorad]) ? (int)trim($cols[$idxNorad]) : 0; if ($norad === 0) { continue; } $total++; $rcsRaw = isset($cols[$idxRcs]) ? trim($cols[$idxRcs]) : ''; if ($rcsRaw === '' || $rcsRaw === '0' || $rcsRaw === '0.0000') { $noRcs++; continue; // kein brauchbarer RCS-Wert } $rcs = (float)$rcsRaw; if ($rcs <= 0) { $noRcs++; continue; } $stmt->execute([':rcs' => $rcs, ':norad' => $norad]); if ($stmt->rowCount() > 0) { $updated++; } else { $skipped++; } } echo "Fertig.\n"; echo " Einträge gesamt: {$total}\n"; echo " rcs aktualisiert: {$updated}\n"; echo " Nicht in DB: {$skipped}\n"; echo " Ohne RCS-Wert: {$noRcs}\n";