Browse Source

fix update del transaction (#6031)

* del transaction

* Update IndexController.php
vic 4 years ago
parent
commit
1d36375b36

+ 1 - 1
frameworks/PHP/one/App/Config/mysql.php

@@ -3,7 +3,7 @@
 return [
     'debug_log' => false, // 是否打印sql日志
     'default'      => [
-        'max_connect_count' => 33,
+        'max_connect_count' => 30,
         'dns'               => env('mysql.default.dns', 'mysql:host=127.0.0.1;dbname=test'),
         'username'          => env('mysql.default.username', 'root'),
         'password'          => env('mysql.default.password', '123456'),

+ 3 - 8
frameworks/PHP/one/App/Controllers/IndexController.php

@@ -53,19 +53,14 @@ class IndexController extends Controller
     {
         $count   = max(min(intval($count), 500), 1);
         $list    = [];
-        $updates = [];
         while ($count--) {
             $row       = World::repeatStatement()->find(mt_rand(1, 10000));
+            $row->randomNumber = mt_rand(1, 10000);
             $list[]    = $row;
-//            $old       = intval($row->randomNumber);
-            $new       = mt_rand(1, 10000);
-            $updates[] = 'update world set randomNumber=' . $new . ' where id=' . $row->id;
         }
-        World::beginTransaction();
-        foreach ($updates as $sql) {
-            $row->exec($sql);
+        foreach($list as $r){
+            $r->repeatStatement()->update(['randomNumber' => $r->randomNumber]);
         }
-        World::commit();
         return $this->json($list);
     }