Chapter 7: Improving the Insert and Update Functions
In the last chapter, I showed you how to break code up into easily reusable functions. This has several advantages:
- the code where the function is called is easier to read
- you can reuse 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 joke ...
Get PHP & MySQL: Novice to Ninja, 7th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.