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

Treehouse

Integrating PHP with Databases Course (How To)

via Treehouse

Overview

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

Syllabus

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

    6:35

  • Introducing Objects

    3:45

  • Working with Objects

    5 questions

  • Getting Started with PDO

    4:13

  • PHP & Databases with PDO

    1 objective

  • Handling Exceptions

    4:23

  • More Exceptions

    4:57

  • 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

    5:20

  • Retrieving Data

    2 objectives

  • Retrieving the Result Set

    3:31

  • Working with Query Results

    4:48

  • Integrating Database Results

    4:22

  • Working with Results

    1 objective

  • Improve with Refactoring

    5:52

  • 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

    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

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

Chevron 8 steps
  • Setting Up the Search Form

    5:35

  • Matching Search Patterns

    5:08

  • Finding Data that Matches a Pattern

    2 objectives

  • Creating the Search Function

    3:10

  • Accounting for Empty Results

    5:32

  • Multiple Conditionals

    3 objectives

  • Combining Search and Pagination

    4:30

  • Final Quiz

    15 questions

Reviews

Start your review of Integrating PHP with Databases Course (How To)

Never Stop Learning.

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

Someone learning on their laptop while sitting on the floor.