Performing CRUD Operations
Create, Read, Update, and Delete data in a database using PHP.
Performing CRUD Operations is a free PHP Academy lesson on CoddyKit — lesson 4 of 6. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the PHP Academy learning path, one of 6 lessons in the course, and your progress syncs across the web and the CoddyKit app.
1
Performing CRUD Operations
Welcome to the next lesson! In this lesson, you’ll learn how to perform the four basic database operations: Create, Read, Update, and Delete (CRUD). These operations are the foundation of dynamic web applications. Let’s get started!

2
What Are CRUD Operations?
CRUD stands for:
- Create: Add new records to the database.
- Read: Retrieve data from the database.
- Update: Modify existing data.
- Delete: Remove data from the database.
Key Point: CRUD operations allow you to manage data dynamically in your applications.
3
Create: Adding Data
Use the INSERT INTO statement to add new records. Example:
Tip: Always use prepared statements to prevent SQL injection.
<?php
$sql = "INSERT INTO users (name, email) VALUES (:name, :email)";
$stmt = $pdo->prepare($sql);
$stmt->execute(["name" => "Alice", "email" => "alice@mail.com"]);
echo "Record added successfully!";
?>
4
Read: Retrieving Data
Use the SELECT statement to fetch data from the database. Example:
Key Point: Use loops to process and display multiple rows of data.
<?php
$sql = "SELECT * FROM users";
$stmt = $pdo->query($sql);
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
echo "ID: " . $row["id"] . ", Name: " . $row["name"] . ", Email: " . $row["email"] . "<br>";
}
?>
5
Update: Modifying Data
Use the UPDATE statement to modify existing records. Example:
Tip: Be careful when using UPDATE without a WHERE clause, as it will update all records.
<?php
$sql = "UPDATE users SET email = :email WHERE name = :name";
$stmt = $pdo->prepare($sql);
$stmt->execute(["email" => "newalice@mail.com", "name" => "Alice"]);
echo "Record updated successfully!";
?>
6
Delete: Removing Data
Use the DELETE statement to remove records. Example:
Key Point: Use the WHERE clause to target specific records for deletion.
<?php
$sql = "DELETE FROM users WHERE name = :name";
$stmt = $pdo->prepare($sql);
$stmt->execute(["name" => "Alice"]);
echo "Record deleted successfully!";
?>
7
Best Practices for CRUD Operations
Follow these best practices when performing CRUD operations:
- Always validate and sanitize user inputs.
- Use prepared statements to prevent SQL injection.
- Back up your database before performing large updates or deletions.
Tip: Log all changes to the database for easier debugging and auditing.
8
Combining CRUD Operations in a Single Application
CRUD operations can be combined in a single application to manage data dynamically. Example:
- Create: Add new users via a form.
- Read: Display user data in a table.
- Update: Edit user information through an interface.
- Delete: Remove users with a delete button.
Key Point: CRUD operations form the backbone of many web applications, including CMS and e-commerce platforms.
9
DELETE FROM users WHERE email = 'alice@mail.com';
10
Great Job!
Congratulations! You’ve learned how to perform CRUD operations in PHP using MySQL. These skills are essential for managing data in any web application. In the next lesson, we’ll explore advanced querying techniques with SQL. Let’s keep coding!

Frequently asked questions
Is the “Performing CRUD Operations” lesson free?
Yes — the full text of “Performing CRUD Operations” is free to read here on the web, and the PHP Academy course includes 6 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the PHP Academy course, upgrade to CoddyKit PRO.
What will I learn in “Performing CRUD Operations”?
Create, Read, Update, and Delete data in a database using PHP. You practise PHP Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start PHP Academy?
No prior experience is required. PHP Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 6, so you can start here or from the beginning and move at your own pace.
How long does the “Performing CRUD Operations” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this PHP Academy lesson?
Yes. Every PHP Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.