I have an array like this :
$services = array(
array("id" => "1", "desc" => "desc 1"),
array("id" => "2", "desc" => "desc 2" ),
......
);
I want to insert those services in TABLE_SERVICE .
each service is inserted if it doesnt exists in TABLE_SERVICE , and deleted it if it exists in TABLE_SERVICE but not in $services array.
I could just delete all records in TABLE_SERVICE and then insert all $services elements ,
but that can be an issue with performance because i often have large set of data in both TABLE_SERVICE and $services .
So is there an efficient way to do this ?
Thanks.
If it was me I’d iterate over
$servicescollecting ids:Then using PHP’s
joinand the select NOT INAfter that, iterate over the array again to insert/update using
ON DUPLICATE KEYSince oracle doesn’t have
ON DUPLICATE KEYthis stackoverflow question might help you with that last part.