--- id: php-mysql-update title: "PHP MySQL Update" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["UPDATE SET", "PHP MySQL μˆ˜μ •"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.88 created_at: 2026-07-04 updated_at: 2026-07-04 review_reason: "" merge_history: [] tags: ["php", "programming", "w3schools", "mysql", "update"] raw_sources: ["https://www.w3schools.com/php/php_mysql_update.asp"] applied_in: [] github_commit: "" --- # [[PHP MySQL Update]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) `UPDATE` shares the exact same danger as `DELETE` β€” omitting `WHERE` updates ALL records in the table, not just none β€” meaning both destructive SQL operations (mass-delete and mass-overwrite) are gated behind the same single safety mechanism, the WHERE clause. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **`UPDATE table SET col=val WHERE condition`** β€” modifies matching records. [S1] - **WHERE limits the blast radius** β€” omitting it updates EVERY record in the table (same risk pattern as DELETE). [S1] - **Executed like DELETE/INSERT** β€” `$conn->query($sql)` (MySQLi OOP), `mysqli_query($conn, $sql)` (procedural), `$conn->exec($sql)` (PDO). [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) - Update by ID: `$sql = "UPDATE MyGuests SET lastname='Doe' WHERE id=2"; if ($conn->query($sql) === TRUE) { echo "Record updated successfully"; } else { echo "Error updating record: " . $conn->error; }`. [S1] - Before/after table state: id=2's lastname changes from "Moe" to "Doe" after the update, all other rows/columns unchanged. [S1] ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) - **WHERE 절 μƒλž΅μ˜ 파괴적 κ²°κ³Ό**: DELETE와 λ§ˆμ°¬κ°€μ§€λ‘œ WHERE μ ˆμ„ μƒλž΅ν•˜λ©΄ ν…Œμ΄λΈ”μ˜ λͺ¨λ“  λ ˆμ½”λ“œκ°€ μˆ˜μ •λœλ‹€λŠ” 점이 λ™μΌν•˜κ²Œ 경고됨. [S1] ## πŸ› οΈ 적용 사둀 (Applied in summary) ν˜„μž¬ 발견된 μ‹€μ œ 적용 사둀가 μ—†μŠ΅λ‹ˆλ‹€ β€” id=2 게슀트의 μ„±λ§Œ λ³€κ²½ν•˜λŠ” 것이 μ•ˆμ „ν•œ 쑰건뢀 μˆ˜μ •μ˜ ν‘œμ€€ νŒ¨ν„΄μ΄λ‹€. [S1] ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Updating a specific record, WHERE clause required (SQL/PHP): ```php $sql = "UPDATE MyGuests SET lastname='Doe' WHERE id=2"; // WHERE prevents updating every row if ($conn->query($sql) === TRUE) { echo "Record updated successfully"; } ``` ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.88 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[PHP Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[PHP MySQL Delete]], [[PHP MySQL Select Limit]] - **μ°Έμ‘° λ§₯락:** λ ˆμ½”λ“œ μˆ˜μ • β€” κ²°κ³Ό μ œν•œ(Select Limit) μ±•ν„°λ‘œ 이어짐. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” PHP MySQL Update Data β€” https://www.w3schools.com/php/php_mysql_update.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "PHP MySQL Update Data" page (Astra wiki-curation, P-Reinforce v3.1 format).