Files
edu/bbs/myclass/_back/_tmp_myclass_diag.php
T

162 lines
6.0 KiB
PHP

<?php
/**
* 마이클래스 구조 진단 파일
* edu_learning_goals와 edu_goal_contents 구조 파악
*/
header('Content-Type: text/html; charset=utf-8');
require_once __DIR__ . '/db_conn.php';
$pdo = db_conn();
echo '<h1>마이클래스 데이터베이스 구조</h1>';
echo '<style>
body { font-family: Arial; margin: 20px; }
table { border-collapse: collapse; margin: 20px 0; width: 100%; }
th, td { border: 1px solid #ccc; padding: 8px; text-align: left; }
th { background: #f0f0f0; }
.ok { color: green; }
.err { color: red; }
h2 { margin-top: 30px; }
</style>';
// 1. 모든 테이블 목록
echo '<h2>1. 전체 테이블 목록</h2>';
$tables = $pdo->query("SHOW TABLES")->fetchAll(PDO::FETCH_COLUMN);
echo '<table><tr><th>테이블명</th></tr>';
foreach ($tables as $t) {
echo "<tr><td>$t</td></tr>";
}
echo '</table>';
// 2. edu_learning_goals 확인
echo '<h2>2. edu_learning_goals 테이블</h2>';
if (in_array('edu_learning_goals', $tables)) {
echo '<b>컬럼 구조:</b>';
$cols = $pdo->query("SHOW COLUMNS FROM edu_learning_goals")->fetchAll();
echo '<table><tr><th>Field</th><th>Type</th><th>Null</th><th>Key</th><th>Default</th></tr>';
foreach ($cols as $c) {
echo "<tr><td>{$c['Field']}</td><td>{$c['Type']}</td><td>{$c['Null']}</td><td>{$c['Key']}</td><td>{$c['Default']}</td></tr>";
}
echo '</table>';
echo '<b>샘플 데이터:</b>';
$rows = $pdo->query("SELECT * FROM edu_learning_goals LIMIT 10")->fetchAll();
if ($rows) {
$keys = array_keys($rows[0]);
echo '<table><tr>' . implode('', array_map(fn($k) => "<th>$k</th>", $keys)) . '</tr>';
foreach ($rows as $r) {
echo '<tr>' . implode('', array_map(fn($v) => '<td>' . htmlspecialchars((string)$v) . '</td>', $r)) . '</tr>';
}
echo '</table>';
} else {
echo '<p class="err">데이터 없음</p>';
}
} else {
echo '<p class="err">테이블 없음</p>';
}
// 3. edu_goal_contents 확인
echo '<h2>3. edu_goal_contents 테이블</h2>';
if (in_array('edu_goal_contents', $tables)) {
echo '<b>컬럼 구조:</b>';
$cols = $pdo->query("SHOW COLUMNS FROM edu_goal_contents")->fetchAll();
echo '<table><tr><th>Field</th><th>Type</th><th>Null</th><th>Key</th><th>Default</th></tr>';
foreach ($cols as $c) {
echo "<tr><td>{$c['Field']}</td><td>{$c['Type']}</td><td>{$c['Null']}</td><td>{$c['Key']}</td><td>{$c['Default']}</td></tr>";
}
echo '</table>';
echo '<b>샘플 데이터:</b>';
$rows = $pdo->query("SELECT * FROM edu_goal_contents LIMIT 20")->fetchAll();
if ($rows) {
$keys = array_keys($rows[0]);
echo '<table><tr>' . implode('', array_map(fn($k) => "<th>$k</th>", $keys)) . '</tr>';
foreach ($rows as $r) {
echo '<tr>' . implode('', array_map(fn($v) => '<td>' . htmlspecialchars((string)$v) . '</td>', $r)) . '</tr>';
}
echo '</table>';
// 통계
echo '<b>통계:</b>';
$stats = $pdo->query("
SELECT
COUNT(DISTINCT goal_id) as goal_cnt,
COUNT(DISTINCT content_id) as content_cnt,
COUNT(*) as total_rows
FROM edu_goal_contents
")->fetch();
echo '<div><p>총 goal_id: ' . $stats['goal_cnt'] . '</p>';
echo '<p>총 content_id: ' . $stats['content_cnt'] . '</p>';
echo '<p>전체 행: ' . $stats['total_rows'] . '</p></div>';
} else {
echo '<p class="err">데이터 없음</p>';
}
} else {
echo '<p class="err">테이블 없음</p>';
}
// 4. 관계도 확인 (learning_goals ↔ goal_contents)
echo '<h2>4. edu_learning_goals ↔ edu_goal_contents 연결</h2>';
if (in_array('edu_learning_goals', $tables) && in_array('edu_goal_contents', $tables)) {
echo '<b>학습목표별 영상 수:</b>';
$rows = $pdo->query("
SELECT
g.goal_id,
g.goal_name,
COUNT(c.content_id) as video_count,
GROUP_CONCAT(c.content_id ORDER BY c.sort_order) as content_ids
FROM edu_learning_goals g
LEFT JOIN edu_goal_contents c ON g.goal_id = c.goal_id
GROUP BY g.goal_id, g.goal_name
ORDER BY g.goal_id
")->fetchAll();
if ($rows) {
echo '<table><tr><th>goal_id</th><th>goal_name</th><th>영상 수</th><th>content_ids</th></tr>';
foreach ($rows as $r) {
echo "<tr>";
echo "<td>{$r['goal_id']}</td>";
echo "<td>{$r['goal_name']}</td>";
echo "<td>{$r['video_count']}</td>";
echo "<td>" . htmlspecialchars($r['content_ids'] ?? '') . "</td>";
echo "</tr>";
}
echo '</table>';
}
}
// 5. 사용자 선택 목표 (if exists)
echo '<h2>5. 사용자별 선택된 학습목표</h2>';
if (in_array('edu_user_goals', $tables)) {
$cols = $pdo->query("SHOW COLUMNS FROM edu_user_goals")->fetchAll();
echo '<table><tr><th>Field</th><th>Type</th></tr>';
foreach ($cols as $c) {
echo "<tr><td>{$c['Field']}</td><td>{$c['Type']}</td></tr>";
}
echo '</table>';
} else if (in_array('edu_goal_user_select', $tables)) {
$cols = $pdo->query("SHOW COLUMNS FROM edu_goal_user_select")->fetchAll();
echo '<table><tr><th>Field</th><th>Type</th></tr>';
foreach ($cols as $c) {
echo "<tr><td>{$c['Field']}</td><td>{$c['Type']}</td></tr>";
}
echo '</table>';
} else {
echo '<p>사용자 선택 테이블을 찾을 수 없습니다.</p>';
}
// 6. 영상 시청 기록 (learning status)
echo '<h2>6. 사용자 학습 진행상황 관련 테이블</h2>';
$learningTables = ['edu_learning_progress', 'edu_user_learning', 'edu_learning_status'];
foreach ($learningTables as $tbl) {
if (in_array($tbl, $tables)) {
echo "<h3>$tbl</h3>";
$cols = $pdo->query("SHOW COLUMNS FROM $tbl")->fetchAll();
echo '<table><tr><th>Field</th><th>Type</th></tr>';
foreach ($cols as $c) {
echo "<tr><td>{$c['Field']}</td><td>{$c['Type']}</td></tr>";
}
echo '</table>';
}
}
?>