DB-Verwaltung

Mini-Admin"; $body .= "
"; $body .= "

Login-Daten werden nur in der Session gespeichert. Für Defaults wird .env aus dem Projekt-Root gelesen.

"; if ($error) $body .= '
' . h($error) . '

'; $body .= "
"; $body .= ""; $body .= "
"; $body .= "
"; $body .= "

"; $body .= "

"; $body .= "

"; $body .= "

"; $body .= "

"; $body .= ""; $body .= "
"; $body .= "
"; $body .= "

Hinweise

"; $body .= "
    "; $body .= "
  • Dieses Tool ist bewusst minimal (Tabellenliste, Browse, SQL Query).
  • "; $body .= "
  • Für produktive Nutzung bitte zusätzlich absichern (Basic Auth / IP-Allowlist).
  • "; $body .= "
"; $body .= "
"; $body .= "
"; $body .= "
"; $body .= "
"; admin_layout('DB-Verwaltung', $body); exit; } // Logged-in area try { $pdo = admin_pdo(); $table = (string)($_GET['t'] ?? ''); $page = max(1, (int)($_GET['p'] ?? 1)); $limit = 50; $offset = ($page - 1) * $limit; $msg = null; $queryResultHtml = ''; if ($_SERVER['REQUEST_METHOD'] === 'POST' && (string)($_POST['action'] ?? '') === 'query') { $sql = trim((string)($_POST['sql'] ?? '')); if ($sql !== '') { // Allow multiple statements? No. Keep minimal & safer. if (preg_match('/;\s*\S/', $sql)) { $msg = ['type' => 'err', 'text' => 'Bitte nur ein Statement ohne zusätzliche Semikolons ausführen.']; } else { try { $stmt = $pdo->query($sql); if ($stmt instanceof PDOStatement) { $rows = $stmt->fetchAll(); $queryResultHtml .= '

Ergebnis

'; $queryResultHtml .= admin_render_table($rows); $msg = ['type' => 'ok', 'text' => 'Query ausgeführt.']; } else { $msg = ['type' => 'ok', 'text' => 'Statement ausgeführt.']; } } catch (Throwable $e) { $msg = ['type' => 'err', 'text' => 'Fehler: ' . $e->getMessage()]; } } } } // Build left nav tables $tables = $pdo->query('SHOW TABLES')->fetchAll(PDO::FETCH_NUM); $body = '
' . '

DB-Verwaltung

eingeloggt
' . '
Logout
' . '
'; $body .= '
'; $body .= '
' . '

Tabellen

' . '
Klick zum Anzeigen
'; if (empty($tables)) { $body .= '
Keine Tabellen gefunden.
'; } else { $body .= ''; } $body .= '
'; $body .= '
'; if ($msg) { $cls = $msg['type'] === 'ok' ? 'ok' : 'err'; $body .= '
' . h($msg['text']) . '

'; } // Browse table if ($table !== '') { // naive identifier quoting for MySQL if (!preg_match('/^[A-Za-z0-9_]+$/', $table)) { $body .= '
Ungültiger Tabellenname.
'; } else { $body .= '

Tabelle: ' . h($table) . '

'; $stmt = $pdo->query('SELECT * FROM `' . $table . '` LIMIT ' . (int)$limit . ' OFFSET ' . (int)$offset); $rows = $stmt->fetchAll(); $body .= admin_render_table($rows); $body .= '
'; if ($page > 1) { $body .= '← Zurück'; } $body .= 'Weiter →'; $body .= '
'; } $body .= '
'; } // Query box $body .= '

SQL Query

'; $body .= '
' . '' . '' . '
' . '
'; $body .= $queryResultHtml; $body .= '
'; // card $body .= '
'; // grid admin_layout('DB-Verwaltung', $body); } catch (Throwable $e) { // Session invalid, force re-login admin_logout(); admin_layout('DB-Verwaltung', '

DB-Verwaltung

' . h($e->getMessage()) . '

Zum Login
'); } function admin_render_table(array $rows): string { if (empty($rows)) { return '
(keine Zeilen)
'; } $cols = array_keys((array)$rows[0]); $html = ''; foreach ($cols as $c) { $html .= ''; } $html .= ''; foreach ($rows as $r) { $html .= ''; foreach ($cols as $c) { $v = $r[$c] ?? null; if ($v === null) { $cell = 'NULL'; } else { $s = (string)$v; $cell = strlen($s) > 500 ? h(substr($s, 0, 500)) . '…' : h($s); } $html .= ''; } $html .= ''; } $html .= '
' . h((string)$c) . '
' . $cell . '
'; return $html; }