Most websites don't just show static pages — they show content stored in a database. Every blog post, product listing, and user profile lives somewhere in a database. PHP and MySQL are the classic duo for making that happen.
What is a Relational Database?
A relational database stores data in tables — just like a spreadsheet. Each table has columns (fields) and rows (records). You can link tables together using keys. For example, a users table might have an id column, and an orders table can reference that same id to know which user placed which order.
MySQL and phpMyAdmin
MySQL is the database engine that stores and manages your data. It's open source, fast, and works beautifully with PHP. phpMyAdmin is a web-based tool that lets you manage MySQL databases visually — create tables, run queries, and browse data without writing SQL by hand. Most local PHP setups like XAMPP or MAMP include both.
Creating a Database and Table
You can create a database with a simple SQL command: CREATE DATABASE mydb. Then create a table with columns and their types. Here's a basic users table with an auto-incrementing ID, a name, and an email field.
<?php
$sql = "CREATE DATABASE mydb";
$sql = "CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100),
email VARCHAR(255)
)";
?>
Try it Yourself →