<?php
require_once($_SERVER['DOCUMENT_ROOT'] . "/session.php");
require_once($_SERVER['DOCUMENT_ROOT'] . "/lib/mydb.php");

$pdo = db_connect();

// juilcar 테이블 구조 확인
$sql = "DESCRIBE " . $DB . ".juilcar";
$stmh = $pdo->query($sql);
$columns = $stmh->fetchAll(PDO::FETCH_ASSOC);

echo "<h3>juilcar 테이블 구조:</h3>";
echo "<table border='1'>";
echo "<tr><th>Field</th><th>Type</th><th>Null</th><th>Key</th><th>Default</th><th>Extra</th></tr>";

foreach ($columns as $column) {
    echo "<tr>";
    echo "<td>" . $column['Field'] . "</td>";
    echo "<td>" . $column['Type'] . "</td>";
    echo "<td>" . $column['Null'] . "</td>";
    echo "<td>" . $column['Key'] . "</td>";
    echo "<td>" . $column['Default'] . "</td>";
    echo "<td>" . $column['Extra'] . "</td>";
    echo "</tr>";
}
echo "</table>";

// initial_distance 컬럼이 있는지 확인
$has_initial_distance = false;
foreach ($columns as $column) {
    if ($column['Field'] === 'initial_distance') {
        $has_initial_distance = true;
        break;
    }
}

if (!$has_initial_distance) {
    echo "<h3>initial_distance 컬럼이 없습니다. 추가하시겠습니까?</h3>";
    echo "<p>다음 SQL을 실행하세요:</p>";
    echo "<code>ALTER TABLE " . $DB . ".juilcar ADD COLUMN initial_distance DECIMAL(10,2) DEFAULT 0.00 COMMENT '최초 주행거리';</code>";
} else {
    echo "<h3>initial_distance 컬럼이 이미 존재합니다.</h3>";
}
?> 