---
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).
