false, 'error' => 'forbidden'], JSON_UNESCAPED_UNICODE); exit; } require_once __DIR__ . '/../bbs/db_conn.php'; if (!function_exists('db_conn')) { http_response_code(500); echo json_encode(['ok' => false, 'error' => 'db_conn_not_found'], JSON_UNESCAPED_UNICODE); exit; } try { $pdo = db_conn(); if (!($pdo instanceof PDO)) { throw new RuntimeException('db_conn_not_pdo'); } $pdo->exec("SET NAMES 'utf8mb4'"); $tables = $pdo->query("SHOW TABLES LIKE 'dash\\_%'")->fetchAll(PDO::FETCH_NUM); $tableNames = array_map(static function ($r) { return (string)$r[0]; }, $tables ?: []); $result = [ 'ok' => true, 'generated_at' => date('c'), 'table_count' => count($tableNames), 'tables' => [], ]; foreach ($tableNames as $table) { $descStmt = $pdo->query("SHOW COLUMNS FROM `" . str_replace('`', '``', $table) . "`"); $columns = $descStmt ? $descStmt->fetchAll(PDO::FETCH_ASSOC) : []; $countStmt = $pdo->query("SELECT COUNT(*) AS cnt FROM `" . str_replace('`', '``', $table) . "`"); $rowCount = $countStmt ? (int)$countStmt->fetchColumn() : 0; $sampleStmt = $pdo->query("SELECT * FROM `" . str_replace('`', '``', $table) . "` LIMIT 3"); $sampleRows = $sampleStmt ? $sampleStmt->fetchAll(PDO::FETCH_ASSOC) : []; $result['tables'][] = [ 'name' => $table, 'row_count' => $rowCount, 'columns' => $columns, 'sample_rows' => $sampleRows, ]; } echo json_encode($result, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); } catch (Throwable $e) { http_response_code(500); echo json_encode([ 'ok' => false, 'error' => 'exception', 'message' => $e->getMessage(), 'type' => get_class($e), ], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); }