"Using PHP with MySQL" was retired on March 1, 2017. You are now viewing the recommended replacement.
- PHP
- Intermediate
About this Course
Building a PHP-driven page is the first step in mastering PHP. The true power of PHP shines when you connect it to a data source like an API or a Database. To introduce you to databases, we'll use an example project -- a Personal Media Library application. We'll refactor this project by replacing an associative array with a database to provide a more robust and scalable tool to store the data in the media library. In the process, you'll learn how to use PDO -- a PHP extension to communicate with a database. You'll also learn about relational databases including how to search for data across multiple tables, as well as how to add common web site features like search forms and pagination.
What you'll learn
- Databases
- Error Handling
- Pagination
- Search
- Refactoring
Databases and PHP
Building a php-driven page is just the first step in mastering PHP. The true power of PHP shines when you connect it to a data source like an API or a Database. In this course, we’ll refactor an existing project to use a database. We’ll then leverage the use of this database for pagination and search capabilities.
8 stepsQuerying the Database with PHP
After the connecting to a database, we can use that database to retrieve the data for our project. We’ll see how to run a select, retrieve the results, and integrate those results into our site.
8 stepsUsing Relational Tables
A relational database can offer you robust and easy interaction with your data. It is built on the relationships between the data. When we are on our details page we need to pull many more details about the specific item, including information from other tables. To do this we’re going to use the relationships in our database to JOIN data from multiple tables. We’ll also use our PHP Data Object to address security concerns.
11 steps-
Understanding Relationship Tables
3:41
-
Relational Data
5 questions
-
Querying Multiple Tables with JOIN
4:02
-
JOINing Tables
1 objective
-
Understanding SQL Injections
5:21
-
SQL Injection
1 question
-
Preparing SQL Statements
6:25
-
Using a Prepared Statement
3 objectives
-
Adding a Secondary Query
4:30
-
Fetching in a While Loop
7:38
-
Fetching Many Relationships
1 objective
Limiting Records in SQL
We will modify our functions to use their own SQL queries to retrieve only the items we need in the first place. As we do this, we'll look at a number of different ways to use SQL-specific features like limits, ordering and aggregate functions to fine tune our queries
13 steps-
Getting Specific with Queries
4:38
-
Filtering Data by Category
6:28
-
Filtering Data
3 objectives
-
Setting Up Pagination Variables
7:43
-
Calculations and Links
5:32
-
Variable and Calculations
5 questions
-
Setting LIMITs
4:52
-
LIMIT and OFFSET
2 objectives
-
Adding Pagination Links
7:05
-
Pagination Function
2 objectives
-
Challenge
1:08
-
Simplifying with a Function
10:24
-
Pagination
5 questions
Filtering Input for Queries
We’re ready to add one of the most important features of any collection. Search capabilities! This is such an important feature, I want to add a search box to every page. Thankfully that’s easy to do because we already have a header file that’s included on all the pages so we can add a search box right below our header bar. Then we’ll make some modification to our catalog page so we can use that same code to display results.
8 stepsTeacher
-
Alena Holligan
After starting out in fine art and moving into graphic design, Alena found her passion for programming over 15 years ago and has never looked back. Alena enjoys community and is excited to introduce people to the wonderful world of PHP and the Portland Tech Community.
When not at her computer, Alena enjoys exploring Portland with her friends and family, including her 3 young children. She also enjoys the Symphony, Cooking, Books, Yarn and Yoga.