📖
단어 치환을 손쉽게 SQL 쿼리로 변환 PHP + HTML 툴: 테이블명, 컬럼명, 치환 목록 입력 → SQL 쿼리 생성

페이지 정보

본문

1. HTML + PHP 코드[code]<?php
// 폼이 제출되었을 때 실행
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    // 입력된 데이터 가져오기
    $table = $_POST['table']; // 테이블명
    $column = $_POST['column']; // 컬럼명
    $replacements = array(); // 치환 목록
    // 치환 목록 받기
    $replacements_raw = $_POST['replacements']; // "기존단어 => 새단어" 형식
    $replacements_lines = explode("\n", $replacements_raw);
    foreach ($replacements_lines as $line) {
        $pair = explode('=>', $line);
        if (count($pair) == 2) {
            $replacements[trim($pair[0])] = trim($pair[1]);
        }
    }
    // REPLACE 중첩 SQL 생성
    $replaceSql = $column;
    foreach ($replacements as $search => $replace) {
        $replaceSql = "REPLACE($replaceSql, '$search', '$replace')";
    }
    // WHERE 조건 (치환 대상만)
    $whereParts = array_map(function($word) use ($column) {
        return "$column LIKE '%$word%'";
    }, array_keys($replacements));
    $whereClause = implode(" OR ", $whereParts);
    // 최종 SQL 출력
    $sql = "UPDATE $table\nSET $column = $replaceSql\nWHERE $whereClause;";
    echo "<pre>$sql</pre>";
}
?>
<!DOCTYPE html>
<html lang="ko">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>SQL 쿼리 생성 툴</title>
</head>
<body>
<h2>SQL 쿼리 생성 툴</h2>
<form method="POST">
    <label for="table">테이블명:</label><br>
    <input type="text" id="table" name="table" required><br><br>
    <label for="column">컬럼명:</label><br>
    <input type="text" id="column" name="column" required><br><br>
    <label for="replacements">치환 목록 (기존단어 => 새단어, 한 줄에 하나):</label><br>
    <textarea id="replacements" name="replacements" rows="10" cols="30" required></textarea><br><br>
    <button type="submit">쿼리 생성</button>
</form>
</body>
</html>[/code]
📜 사용법
1. 테이블명과 컬럼명을 입력합니다.
2. 치환 목록은 다음과 같은 형식으로 입력합니다:[code]지우개 => 무지개
연필 => 형광펜
공책 => 노트
가방 => 백팩
샤프 => 샤프펜슬[/code]
3. 폼을 제출하면, 자동으로 SQL 쿼리가 생성되어 화면에 출력됩니다.

🚀 실행 예시
1. 입력 예시
테이블명: zetyx_board_missav
컬럼명: subject
치환 목록:[code]지우개 => 무지개
연필 => 형광펜
공책 => 노트
가방 => 백팩
샤프 => 샤프펜슬[/code]
2. 생성된 SQL 쿼리[code]UPDATE zetyx_board_missav
SET subject = REPLACE(
    REPLACE(
        REPLACE(
            REPLACE(
                REPLACE(
                    REPLACE(subject, '지우개', '무지개'),
                '연필', '형광펜'),
            '공책', '노트'),
        '가방', '백팩'),
    '샤프', '샤프펜슬')
WHERE subject LIKE '%지우개%' OR subject LIKE '%연필%' OR subject LIKE '%공책%' OR subject LIKE '%가방%' OR subject LIKE '%샤프%';[/code]이 툴을 사용하면 다양한 단어 치환을 손쉽게 SQL 쿼리로 변환할 수 있습니다.
실제 사용할 때는 테이블명과 컬럼명만 정확히 입력하고, 치환하려는 단어들을 추가하면 됩니다.

필요하시면 툴에서 출력된 쿼리를 직접 복사하여 phpMyAdmin이나 다른 DB 관리 툴에서 실행할 수 있습니다.

댓글목록

등록된 댓글이 없습니다.


자료 목록
번호 제목 날짜
173
🫧
04-17
172
🫧
04-17
171
🫧
04-16
📖
🫧
04-15
169
🫧
04-15
168
🫧
04-13
167
🫧
04-13
166
🫧
04-13
165
🫧
04-13
164
🫧
04-13
163
🫧
04-10
162
🫧
04-10
161
🫧
04-09
160
🫧
04-09
159
🫧
04-08

🔍 검색

회사소개 개인정보처리방침 서비스이용약관
Copyright © rainbowgarden.shop All rights reserved.