prepare("SELECT id FROM users WHERE username = ? LIMIT 1"); $stmt->execute([$username]); if ($stmt->fetch()) { throw new RuntimeException('이미 사용 중인 아이디입니다.'); } $hash = password_hash($password, PASSWORD_DEFAULT); $stmt = $pdo->prepare(" INSERT INTO users (username, password_hash, created_at) VALUES (?, ?, NOW()) "); $stmt->execute([$username, $hash]); $userId = (int)$pdo->lastInsertId(); $stmt = $pdo->prepare("SELECT * FROM users WHERE id = ? LIMIT 1"); $stmt->execute([$userId]); $user = $stmt->fetch(); login_user($user, true); header('Location: /dashboard.php'); exit; } catch (Throwable $e) { $error = $e->getMessage(); } } ?>