Let's say I have a prepared query:
$update_rq = $DB->prepare("
UPDATE `table`
SET
`A` = :a,
`B` = :b,
`C` = :c
WHERE `id` = :id
LIMIT 1
");
If I will execute this query with the following code:
$update_rq->execute(['id' => $id,'a' => 1,'b' => 2]);
I think that this query will set C
column with NULL
value (if this column can have NULL value or it will throw an error if it can not).
Can I modify the prepare
or execute
statements to change this behavior to keep C
column unchanged (SET C = C
) if the corresponding variable is unset (equals to NULL)?
Another approach: Probably I could fetch row prior to update, change needed columns and than update with new values?