From the course: PHP: Object-Oriented Programming with Databases

Unlock the full course today

Join today to access over 22,700 courses taught by industry experts or purchase this course individually.

Define query methods

Define query methods - PHP Tutorial

From the course: PHP: Object-Oriented Programming with Databases

Start my 1-month free trial

Define query methods

- [Instructor] Now that our bicycle class knows what database connection it should use, we're ready to start defining query methods on the bicycle class. In the previous movie, we used that database connection inside the bicycle class to execute a query. What I want to do now is move that query inside the class. The reason why is that it makes sense that a bicycle class ought to know how to retrieve all of the bicycles that are stored in the database. So what we essentially want to do is move these two lines into our class. So I'm just going to copy those two lines, and what I want to have instead here is I just want to be able to call find all, right? If I just call find all on the bicycle class, it ought to be able to turn back a result to me. Now notice that I'm calling this as a class method, not an instance method. I don't have an instance of bicycle. I haven't found any yet. I'm telling the class that it should use find all. All right, so let's save that. Remember, I already…

Contents