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 7: Improving the Insert and Update Functions

In the last chapter, I showed you how to break the code up into easily reusable functions. This has several advantages:

  • the code where the function is called is easier to read
  • you can re-use the same function from anywhere

In this chapter, I’ll take this a step further and show you how to make a function that could be used for any database table, and then show you how object-oriented programming can simplify this task even further.

Improving the Update Function

updateJoke($pdo, 1, 'Why did the programmer quit his job? He didn\'t get arrays', 1);
                

To run this function, all of the arguments for the function must be provided:

  • joke ID
  • joke text
  • author ID

What if you just wanted to update the ...

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