Define a query method that will find a single record in the database and return it as a PHP object with properties set to the record values.
- [Instructor] In the previous movie, we retrieved…all bicycle records from the database and built…new objects whose properties had those same values.…In this movie, we're going to learn how to retrieve…a single record from the database.…This is very common, to want to be able…to review all records and then also…to be able to focus in on a single record.…Let's switch over to our bicycle…class and we already have find all.…What I want to write now is another method, static public…function, and it's going to be called find by ID.…
So the idea is that we're going to pass in the ID…of the record that we want to it,…and it's going to retrieve only that record.…So let's start by writing the SQL that we're going to need.…So I'll write SQL equals and this is…also going to be a select all from bicycles.…I'm going to put a space at the end,…because I'm going to keep this line going.…I'm going to just append it to a new line.…And this one is going to be where ID equals…and then inside single quotes I'm going…to put the ID that we want to retrieve.…
Note: This is an intermediate-level training course that assumes you have existing knowledge of PHP. To refresh your skills, check out PHP Essential Training and PHP: Object-Oriented Programming.
- Creating a project database and tables
- Connecting to the database
- Database queries with OOP
- The active record design pattern
- Defining a database-driven class
- Performing common database tasks with OOP
- Creating inheritable and reusable code
- Object-oriented user authentication
- Object-oriented pagination
Skill Level Intermediate
Consuming RESTful APIs in PHP with Guzzlewith Justin Yost2h 12m Intermediate
PHP: Accessing Databases with PDO and MySQLiwith David Powers3h 47m Intermediate
1. Overview and Project Setup
2. The Database Connection
3. Define a Database-Driven Class
4. Object-Oriented CRUD
5. Object-Oriented Authentication
6. Object-Oriented Pagination
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.