#Multiple updates#
I think overall your code looks good, though someone who is better with PHP would be better placed to review that aspect of it. I saw part of your question was how to update multiple fields at the same time. You can create a stored PROCEDURE in MySQL and pass parameters for multiple updates at the same time. If you write it correctly you can use IF...THEN statements to tell MySQL to skip NULL input parameters.
I would also suggest to make the updates as part of a TRANSACTION so your database is in a consistent state, in other words all the updates will be committed at the same time while the affected records are locked during the transaction. Here goes:
DELIMITER $$
CREATE OR UPDATE PROCEDURE update_data(
-- first update params
IN table1 VARCHAR,
IN column1 VARCHAR,
IN value1 VARCHAR,
IN id1 VARCHAR,
IN id_value1 INT,
-- second update params
IN table2 VARCHAR,
IN column2 VARCHAR,
IN value2 VARCHAR,
IN id2 INT,
IN id_value1 INT
-- repeat as needed
)
BEGIN
START TRANSACTION;
-- first update
IF table1 IS NOT NULL THEN
UPDATE table1 SET column1 = value1 WHERE id1 = id_value1;
ENDIF;
-- second update
IF table2 IS NOT NULL THEN
UPDATE table2 SET column2 = value2 WHERE id2 = id_value2;
ENDIF;
-- repeat as needed
COMMIT;
END$$$$
DROP PROCEDURE IF EXISTS update_data $$
CREATE PROCEDURE update_data (
-- first update params
IN column1 TEXT,
IN value1 TEXT,
IN id_value1 TEXT,
-- second update params
IN column2 TEXT,
IN value2 TEXT,
IN id_value2 TEXT
-- repeat as needed
)
BEGIN
START TRANSACTION;
-- first update
IF table1 IS NOT NULL THEN
UPDATE polisy_oc SET column1 = value1 WHERE numer_polisy_oc = id_value1;
END IF;
-- second update
IF table2 IS NOT NULL THEN
UPDATE polisy_oc SET column2 = value2 WHERE numer_polisy_oc = id_value2;
END IF;
-- repeat as needed
COMMIT;
END $$
DELIMITER ;
Once the procedure is created, the SQL syntax to call it is:
CALL PROCEDURE(table1, column1, value1, id1, id_value1, table2, column2, value2, id2, id_value2) -- etc.
So in PHP it would look something like this for one single update. You would need to mofidy your PHP script of course to accomodate more input parameters, but you look like your know your PHP stuff so I'm sure you can figure that part out.
$update = $this->db_connection->prepare("CALL update_data({$update_headers['table']}, $key, ?, {$update_headers['id']}, ?");