--- id: php-mysql-create-db title: "PHP MySQL Create DB" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["CREATE DATABASE", "PHP MySQL DB 생성"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.89 created_at: 2026-07-04 updated_at: 2026-07-04 review_reason: "" merge_history: [] tags: ["php", "programming", "w3schools", "mysql", "database"] raw_sources: ["https://www.w3schools.com/php/php_mysql_create.asp"] applied_in: [] github_commit: "" --- # [[PHP MySQL Create DB]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) Connecting to CREATE a database omits the database-name argument entirely β€” `new mysqli($servername, $username, $password)` has only 3 arguments, unlike the 4-argument connection used everywhere else, since the database you're about to create doesn't exist yet to connect to. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **`CREATE DATABASE dbname`** β€” the SQL command to create a database. [S1] - **3-argument connection for creation** β€” no database name yet, since it doesn't exist. [S1] - **Requires admin privileges** β€” creating/deleting databases needs administrative access. [S1] - **`$conn->query($sql)`** (MySQLi OOP) β€” executes the CREATE DATABASE statement, returns `true` on success. [S1] - **`$conn->exec($sql)`** (PDO) β€” the PDO equivalent for executing a non-SELECT statement. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) - MySQLi OOP: `$conn = new mysqli($servername, $username, $password); $sql = "CREATE DATABASE myDB"; if ($conn->query($sql) === TRUE) { echo "Database created successfully"; } else { echo "Error creating database: " . $conn->error; }`. [S1] - MySQLi procedural: `$conn = mysqli_connect($servername, $username, $password); if (mysqli_query($conn, $sql)) { echo "Database created successfully"; }`. [S1] - PDO: `$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password); ... $conn->exec($sql); echo "Database created successfully";` β€” wrapped in try/catch(PDOException). [S1] ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) μ†ŒμŠ€μ—μ„œ λͺ¨μˆœλ˜λŠ” μ •λ³΄λŠ” νŠΉλ³„νžˆ μ—†μœΌλ‚˜, DB 생성 μ‹œ μ—°κ²° μΈμžκ°€ 3κ°œλΏμ΄λΌλŠ” 점이 λ‹€λ₯Έ λͺ¨λ“  μ±•ν„°μ˜ 4개 인자 νŒ¨ν„΄κ³Ό μœ μΌν•˜κ²Œ 닀름. [S1] ## πŸ› οΈ 적용 사둀 (Applied in summary) ν˜„μž¬ 발견된 μ‹€μ œ 적용 사둀가 μ—†μŠ΅λ‹ˆλ‹€ β€” myDBλΌλŠ” μ΄λ¦„μ˜ λ°μ΄ν„°λ² μ΄μŠ€λ₯Ό μƒμ„±ν•˜λŠ” 것이 이후 ν…Œμ΄λΈ” 생성 μ±•ν„°μ˜ μ „μ œ 쑰건이닀. [S1] ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Creating a database with only 3 connection arguments (PHP): ```php $conn = new mysqli($servername, $username, $password); // no dbname yet $sql = "CREATE DATABASE myDB"; if ($conn->query($sql) === TRUE) { echo "Database created successfully"; } ``` ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.89 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[PHP Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[PHP MySQL Connect]], [[PHP MySQL Create Table]] - **μ°Έμ‘° λ§₯락:** λ°μ΄ν„°λ² μ΄μŠ€ 생성 β€” ν…Œμ΄λΈ” 생성(Create Table) μ±•ν„°λ‘œ 직접 이어짐. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” PHP Create a MySQL Database β€” https://www.w3schools.com/php/php_mysql_create.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "PHP Create a MySQL Database" page (Astra wiki-curation, P-Reinforce v3.1 format).