PHP MySQL Create Table
🗄️ PHP MySQL Create Table Tutorial
After creating a database, PHP MySQL Create Table to store your data. PHP can execute SQL CREATE TABLE statements using mysqli or PDO.
1️⃣ Using mysqli (Procedural)
Explanation:
-
id→ Primary key, auto-incremented -
name→ VARCHAR, cannot be NULL -
email→ UNIQUE constraint -
age→ Integer -
reg_date→ Timestamp, default is current time
2️⃣ Using mysqli (Object-Oriented)
3️⃣ Using PDO
✅ PDO::exec() is used for queries that don’t return results like CREATE, UPDATE, DELETE.
4️⃣ Key Points
-
Data types: INT, VARCHAR, TEXT, DATE, TIMESTAMP, etc.
-
Constraints:
-
PRIMARY KEY→ unique identifier -
UNIQUE→ prevents duplicate values -
NOT NULL→ column cannot be empty -
AUTO_INCREMENT→ automatically increments numeric field
-
-
Always check connection and query errors.
-
Tables must be created inside an existing database.
