Class Central is learner-supported. When you buy through links on our site, we may earn an affiliate commission.


Integrating PHP with Databases Course

via Treehouse


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.

Chevron 8 steps
  • Getting to Know the Project


  • Introducing Objects


  • Working with Objects

    5 questions

  • Getting Started with PDO


  • PHP & Databases with PDO

    1 objective

  • Handling Exceptions


  • More Exceptions


  • Exception Handling

    5 questions

Querying 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.

Chevron 8 steps
  • Querying the Database


  • Retrieving Data

    2 objectives

  • Retrieving the Result Set


  • Working with Query Results


  • Integrating Database Results


  • Working with Results

    1 objective

  • Improve with Refactoring


  • Refactoring

    2 questions

Using 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.

Chevron 11 steps
  • Understanding Relationship Tables


  • Relational Data

    5 questions

  • Querying Multiple Tables with JOIN


  • JOINing Tables

    1 objective

  • Understanding SQL Injections


  • SQL Injection

    1 question

  • Preparing SQL Statements


  • Using a Prepared Statement

    3 objectives

  • Adding a Secondary Query


  • Fetching in a While Loop


  • 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

Chevron 13 steps
  • Getting Specific with Queries


  • Filtering Data by Category


  • Filtering Data

    3 objectives

  • Setting Up Pagination Variables


  • Calculations and Links


  • Variable and Calculations

    5 questions

  • Setting LIMITs



    2 objectives

  • Adding Pagination Links


  • Pagination Function

    2 objectives

  • Challenge


  • Simplifying with a Function


  • 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.

Chevron 8 steps
  • Setting Up the Search Form


  • Matching Search Patterns


  • Finding Data that Matches a Pattern

    2 objectives

  • Creating the Search Function


  • Accounting for Empty Results


  • Multiple Conditionals

    3 objectives

  • Combining Search and Pagination


  • Final Quiz

    15 questions


Start your review of Integrating PHP with Databases Course

Never Stop Learning.

Get personalized course recommendations, track subjects and courses with reminders, and more.