File tree Expand file tree Collapse file tree 4 files changed +30
-2
lines changed
Expand file tree Collapse file tree 4 files changed +30
-2
lines changed Original file line number Diff line number Diff line change 4141 'busy_timeout ' => null ,
4242 'journal_mode ' => null ,
4343 'synchronous ' => null ,
44+ 'transaction_mode ' => 'DEFERRED ' ,
4445 ],
4546
4647 'mysql ' => [
Original file line number Diff line number Diff line change 33namespace Illuminate \Database \Concerns ;
44
55use Closure ;
6+ use Illuminate \Database \Connection ;
67use Illuminate \Database \DeadlockException ;
78use RuntimeException ;
89use Throwable ;
910
11+ /**
12+ * @mixin Connection
13+ */
1014trait ManagesTransactions
1115{
1216 /**
@@ -148,7 +152,7 @@ protected function createTransaction()
148152 $ this ->reconnectIfMissingConnection ();
149153
150154 try {
151- $ this ->getPdo ()-> beginTransaction ();
155+ $ this ->executeBeginTransactionStatement ();
152156 } catch (Throwable $ e ) {
153157 $ this ->handleBeginTransactionException ($ e );
154158 }
@@ -184,7 +188,7 @@ protected function handleBeginTransactionException(Throwable $e)
184188 if ($ this ->causedByLostConnection ($ e )) {
185189 $ this ->reconnect ();
186190
187- $ this ->getPdo ()-> beginTransaction ();
191+ $ this ->executeBeginTransactionStatement ();
188192 } else {
189193 throw $ e ;
190194 }
Original file line number Diff line number Diff line change @@ -1493,6 +1493,16 @@ public function unsetTransactionManager()
14931493 $ this ->transactionsManager = null ;
14941494 }
14951495
1496+ /**
1497+ * Run the statement to start a new transaction.
1498+ *
1499+ * @return void
1500+ */
1501+ public function executeBeginTransactionStatement ()
1502+ {
1503+ $ this ->getPdo ()->beginTransaction ();
1504+ }
1505+
14961506 /**
14971507 * Determine if the connection is in a "dry run".
14981508 *
Original file line number Diff line number Diff line change @@ -100,4 +100,17 @@ protected function getDefaultPostProcessor()
100100 {
101101 return new SQLiteProcessor ;
102102 }
103+
104+ public function executeBeginTransactionStatement ()
105+ {
106+ if (version_compare (PHP_VERSION , '8.4.0 ' )) {
107+ $ mode = $ this ->getConfig ('transaction_mode ' ) ?? 'DEFERRED ' ;
108+
109+ $ this ->getPdo ()->exec ("BEGIN $ mode TRANSACTION " );
110+
111+ return ;
112+ }
113+
114+ $ this ->getPdo ()->beginTransaction ();
115+ }
103116}
You can’t perform that action at this time.
0 commit comments