हम सभी DB::transaction()कई सम्मिलित प्रश्नों के लिए उपयोग करते हैं। ऐसा करते समय, try...catchइसे अंदर रखा जाना चाहिए या इसे लपेटना चाहिए? क्या यह भी आवश्यक है कि try...catchजब कुछ गलत हो जाए तो लेनदेन स्वचालित रूप से विफल हो जाएगा?
try...catchएक लेनदेन लपेटकर नमूना :
// try...catch
try {
// Transaction
$exception = DB::transaction(function() {
// Do your SQL here
});
if(is_null($exception)) {
return true;
} else {
throw new Exception;
}
}
catch(Exception $e) {
return false;
}
विपरीत, एक DB::transaction()कोशिश लपेटकर ... पकड़:
// Transaction
$exception = DB::transaction(function() {
// try...catch
try {
// Do your SQL here
}
catch(Exception $e) {
return $e;
}
});
return is_null($exception) ? true : false;
या बस एक लेनदेन w / o कोशिश ... पकड़
// Transaction only
$exception = DB::transaction(function() {
// Do your SQL here
});
return is_null($exception) ? true : false;