Let’s say I have a regular prepare statement, but sometimes I must omit some columns from being updated:
$stmt = $db->prepare("UPDATE table SET price = ?, size = ?, color = ? WHERE id = ? LIMIT 1");
In most cases the execution would be like this:
$stmt->execute([ $price, $size, $color, $id ]);
But in some cases I have to omit some columns from being changed.
For example:
if( $weight == 0 ) {
// in this case I must omit the weight column and keep the current value in the database. I don't need the zero in there
}
Any smart ways of including/removing columns for the query?