Update with less arguments

25th Jun 18

You can change a php function so that rather than requiring specific arguments that are specific to the table, you can create a more generic UPDATE function. 

In the below update function we require the authorid, id and joketext as arguments:

function updateJoke($pdo, $jokeId, $joketext, $authorId){
  $parameters = [':joketext'=>$joketext, ':authorId'=>$authorId, ':id'=>$jokeId];
  query($pdo,'UPDATE `joke` SET `authorid` = :authorId, `joketext`= :joketext
              WHERE `id` = :id', $parameters);


I have recently completed my apprenticeship.  I am currently building the API to a React JS site using Firebase.