PHP CHAPTER 29

MySQL Database

MySQL is a relational database management system used to store structured data.

📘

What is it?

MySQL is a relational database management system used to store structured data.

💡

Why do we use it?

It provides persistent storage for students, courses, payments, products and users.

⚙️

How does it work?

PHP sends SQL commands to the MySQL server through a database connection.

🧩

Syntax

PHP Syntax
CREATE DATABASE database_name;
💻

Example

PHP Example
CREATE DATABASE aifa_php_lab;
🔍

Example Explained

CREATE DATABASE asks MySQL to create a new database named aifa_php_lab.
🚀

More Examples

CREATE DATABASE IF NOT EXISTS aifa_php_lab;

⚠️ Important Rules

Database names should be clear and meaningful.

❌ Common Mistakes

Trying to select a database that does not exist.

🌍 Real-World Use

Student management systems, e-commerce and CMS applications.

📝 Practice Exercise

Create a database named aifa_php_lab using phpMyAdmin.

💻 Try It Yourself

Write and run this PHP lesson inside the AIFA Coding Lab.

Open Coding Lab →