Answer the question
In order to leave comments, you need to log in
Mysql block transaction by foreign key?
Hello. There is a code, in php + laravel + mysql, that behind the scenes executes a transaction in mysql:
DB::transaction(function () use (&$game, &$bet, $items, $user) {
$bet->user()->associate($user);
$bet->game()->associate($game);
$bet->save();
$this->inventoryService->move($items, $bet);
$game->save();
});
Answer the question
In order to leave comments, you need to log in
Honestly, it is not clear why you need to exit with an error. If the first transaction is still running, then the second one will simply wait for its completion and work later. From the point of view of the DBMS, there is no error, so it cannot be caught. An error can occur if only a "deadlock" (deadlock) has occurred, then one of the transactions is fired and you can get a message about it from the DBMS.
But if you really want to receive a message, then first check if the table is not locked before starting the transaction, and if so, issue a message, and do not start the transaction.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question