I have a foreach loop that iterates each row of an excel file. With the data I retrieve from the single row I run some query that select or insert some data in my db. Example of one query I run:
if($error == ''){
try{
$s2 = $pdo->prepare("SELECT anagrafiche.id_ndg FROM anagrafiche
WHERE anagrafiche.cod_fisc = '$cf_cedente'
OR anagrafiche.p_iva = '$cf_cedente'
OR anagrafiche.cf_estero = '$cf_cedente'");
$s2->execute();
}
catch (PDOException $e){
$error = 'Errore nel trovare anagrafica cedente: '.$e->getMessage();
echo 'Non trovato cedente con codice fiscale '.$cf_cedente.' ';
}
}
This situation ends up with a lot of nested if because I don't want some query to run if an error is thrown at a specific point. Would it be better in terms of execution time or resources if I use continue to stop the current row to be executed and jump to the next instead of this situation? So that the code would look like:
try{
$s2 = $pdo->prepare("SELECT anagrafiche.id_ndg FROM anagrafiche
WHERE anagrafiche.cod_fisc = '$cf_cedente' OR anagrafiche.p_iva =
'$cf_cedente' OR anagrafiche.cf_estero = '$cf_cedente'");
$s2->execute();
}
catch (PDOException $e){
$error = 'Errore nel trovare anagrafica cedente: '.$e->getMessage();
echo 'Non trovato cedente con codice fiscale '.$cf_cedente.' ';
}
if($error!=''){
echo $error;
continue;
}
Or there is an even better option I haven't thought about yet? Thank you for your help! Note: I am doing a massive data load so I need continue to load the next row skipping the one that is in error.