I'm parsing an xml file which I loop through and store information into a SQL Server. I send a MERGE
query to either insert or update information.
Is it best to store this information in a variable, and send query after the loop has finished, or send numerous small queries within the loop? I expect 60-100 queries for each loop.
$DOM=simplexml_load_file($url);
$info=$DOM->info;
foreach($info as $i){
$i_name=$i['name'];
$i_id=$i['id'];
...
$q=sqlsrv_query($conn,"
MERGE dbo.members m USING (
SELECT
'$i_name' as name,
'$i_id' as id,
...
) s ON ( m.id=s.id )
WHEN MATCHED THEN
UPDATE SET ...
WHEN NOT MATCHED THEN
INSERT ...
");
}