Преглед на файлове

fix update (#6005)

* ä¿fix update

* updat
vic преди 4 години
родител
ревизия
8698c2c393
променени са 2 файла, в които са добавени 17 реда и са изтрити 16 реда
  1. 1 1
      frameworks/PHP/one/App/Config/mysql.php
  2. 16 15
      frameworks/PHP/one/App/Controllers/IndexController.php

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

@@ -3,7 +3,7 @@
 return [
     'debug_log' => false, // 是否打印sql日志
     'default'      => [
-        'max_connect_count' => 20,
+        'max_connect_count' => 33,
         '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'),

+ 16 - 15
frameworks/PHP/one/App/Controllers/IndexController.php

@@ -34,15 +34,15 @@ class IndexController extends Controller
     public function fortunes()
     {
         $data   = Fortune::findAll()->jsonSerialize();
-        $data[] = (object) ['id' => 0,'message' => 'Additional fortune added at request time.'];
-        usort($data, function ($a,$b){
+        $data[] = (object)['id' => 0, 'message' => 'Additional fortune added at request time.'];
+        usort($data, function ($a, $b) {
             return $a->message <=> $b->message;
         });
 
         $html = '';
         foreach ($data as $f) {
             $f->message = htmlspecialchars($f->message, ENT_QUOTES, 'UTF-8');
-            $html    .= "<tr><td>{$f->id}</td><td>{$f->message}</td></tr>";
+            $html       .= "<tr><td>{$f->id}</td><td>{$f->message}</td></tr>";
         }
 
         $this->response->header('Content-type', 'text/html; charset=UTF-8');
@@ -51,20 +51,21 @@ class IndexController extends Controller
 
     public function updates($count = 1)
     {
-        $count = max(min(intval($count), 500), 1);
-        $list  = [];
-        $updates = ['begin'];
+        $count   = max(min(intval($count), 500), 1);
+        $list    = [];
+        $updates = [];
         while ($count--) {
-            $row    = World::repeatStatement()->find(mt_rand(1, 10000));
-            $list[] = $row;
-            $old = intval($row->randomNumber);
-            do {
-                $new = mt_rand(1, 10000);
-            } while($old === $new);
-            $updates[] = 'update world set randomNumber='.$new.' where id='.$row->id;
+            $row       = World::repeatStatement()->find(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);
         }
-        $updates[] = 'commit;';
-        $row->exec(implode(';',$updates));
+        World::commit();
         return $this->json($list);
     }