
The spiral approach is a technique often used in teaching or textbooks where first the basic facts of a subject are learned, without worrying about details. Then as learning progresses, more and more details are introduced, while at the same time they are related to the basics which are reemphasized many times to help enter them into long-term memory. Last edit: September 2019.
The PDO API needs a specific driver to communicate with a database. Each database system has its own PDO driver to communicate with PHP. Last edit: September 2019.
You can use any PHP development environment you may already have. In his demonstrations, the author uses XAMPP with PHP 7.3, along with the Visual Code editor.
This video shows you how to create a database using phpMyAdmin. The purpose of this database is to have data for testing the PHP 7 script exercises. You may skip this video if you already know how to create a database. You will need a database with 1 table and at least 2 rows with a title and a content column.
This is an optional practicing exercise.
NOTE: If you are using XAMPP, please write your PHP code inside of the htdocs folder. Create your project folder and then open the folder with your favorite code editor.
In this video, you will see how to create a basic PHP connection to a database using PDO. This is a hands on exercise but it could also be used for reviewing concepts.
In this lecture we move all database credential values to separate variables.
This is an optional practicing exercise. The result follows on the next session.
Code for connection to the MySQL database blogs.
When creating a PDO connection instance you may not want a connection error bubble up to a site-wide handler. This video shows you how to create a try catch statement to catch a possible connection error and control the outcome as you may wish.
This is a document containing a sample of the discussed script for your review. Links to related resources are included. Content may be updated at times. Please check periodically.
In this project, we are going to read values from the database. This exercise reviews and creates a new file for connecting to the database. Alternatively, you can copy the code from the last project.
In this exercise, we discuss one of two ways for querying a database using the PDO class.
Using the fetch method to access database records. Looping items to screen. Error handling.
Final code configuration for the previous exercise
This lecture discusses the problem of HTML entities arriving at the browser from a database, and how to make sure the browser does not convert them into HTML tags.
Final code configuration for the previous exercise
This exercise shows how to assign an SQL statement to a variable and then use the variable as the query argument. It also makes a brief introduction to the Prepare and Execute functions.
Final code configuration for the previous exercise
In this exercise, we are going to create a new file with a new connection for upcoming lectures.
How to create a query-template by using a placeholder instead of an ID value. This is the first part of using PHP 7 Prepared Statements.
How to execute a PDO Prepared Statement. Introduction to rowCount.
Final code configuration for the previous exercise
Learn how to build named placeholders in PHP 7 PDO
How to replace the Query function for a combination of Prepare & Execute. Run multiple Executes.
Final code configuration for the previous exercise
This is a review lecture. Here, a new file called dbinsert.php will be created. You may skip this video if you are using the same file for all exercises.
Exercise initial code configuration
This video covers how to add an INSERT statement to the prepare function, and then execute the real data. In the end, we will have a new record in the database. The function bindValue is also introduced but not used.
Exercise final code configuration
In this exercise we see how to display the number of affected rows by using the method rowCount.
How to fetch the last inserted ID and display the contents on screen.
Adding HTML entities to prevent browser misinterpretation
Exercise final code configuration
Exercise initial code configuration
How to update a record using prepared statements
Final code configuration for the previous exercise
Exercise initial code configuration
How to delete a database record using prepared statements
Exercise final code configuration
How to include database credentials on multiple files
How to add an htaccess file to make a folder invisible from the browser
Difference between fetch with no arguments versus adding PDO::FETCH_ASSOC
Prepared Statements Emulation; When to use and when not to use
How to disable Prepared Statements Emulation and how to use bindValue.
Why is PDO important?
PDO provides a data-access abstraction layer in PHP, which means that, regardless of what database you're using, you write the same functions to issue queries and fetch data. It's that simple! However, you still need to set a database-specific PDO driver in your php.ini to access the correct database server.
How is this course different?
This is a hands-on project; no fluff or history lessons that you can always search if you're interested.
This updated course was originally written in 2019 using PHP 7.3,
but it has been reviewed in 2024 using PHP 8.2 to assure its integrity.
Each section starts with independent code after a brief review of concepts.
Wash, Rinse, and Repeat.
Upon completion of this project, you should be able to:
Summarize and remember the steps involved in using PHP to accomplish a basic database connection and CRUD.
Have a solid foundation to take other courses involving PHP and database connections, like using Symfony components, for example.
Your PDO training starts here.
The purpose of this short course is to empower you by giving you the basics before you tackle a framework where everything is more abstract. It's a short study project designed to go slow by repeating core exercises.
Why PHP?
In 2025, PHP still powers 76% of websites around the world. PHP has evolved into a powerful, object oriented language. We are not in 2005 anymore. The job market is wide open for good PHP developers that take time to study fundamentals.
This project informs and teaches; and that is great for reviewing concepts as well.
Add it to your collection of periodic drills you must do to stay current with the basics.
Subscribe today, even if you want to start at a later date.