71 lines
2.2 KiB
PHP
71 lines
2.2 KiB
PHP
<?php
|
|
// Temporary diagnostics for dash_* tables.
|
|
// Remove this file after verification.
|
|
declare(strict_types=1);
|
|
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
|
|
$key = (string)($_GET['key'] ?? '');
|
|
if ($key !== 'baroncs-dash-probe-20260409') {
|
|
http_response_code(403);
|
|
echo json_encode(['ok' => 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);
|
|
}
|