function can be a big help in constructing SQL statements. Push the SET-parts onto one array as you push the bind-values onto the other. Then construct your SQL with something clear like:
This will insert comma between the elements without adding an extra one on the end,
it lets you create the SQL statement itself in just one place. This will prove to be vastly easier to debug, and to modify in the future.