O'Reilly logo

PHP & MySQL: Novice to Ninja, 6th Edition by Kevin Yank, Tom Butler

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 8: Objects and Classes

In the last chapter, I showed you how to write generic, reusable functions that could be used to manipulate any database table. In this chapter, we’ll move those functions into a class, to avoid some of the repetition that’s needed when they’re used.

One of the biggest problems with functions is that all the information they need to execute has to be sent to them in arguments. In the case of the delete function we wrote, there are four pieces of information:

  • the $pdo database instance
  • the name of the table to delete from
  • the name of the primary key field
  • the value to delete

The same is true of all the functions—findById, findAll, update, insert and save. Each of the functions we created needs to be passed at ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required