stanley-king 2 tahun lalu
induk
melakukan
a1fc51dc36
3 mengubah file dengan 56 tambahan dan 6 penghapusan
  1. 22 4
      core/framework/db/mysqli.php
  2. 2 2
      data/config/dev/base.ini.php
  3. 32 0
      mobile/control/mtest.php

+ 22 - 4
core/framework/db/mysqli.php

@@ -608,12 +608,30 @@ class Db
 
     public static function beginTransaction($host = 'master')
     {
-        self::init_link();
+        $count = 0;
+        while (true)
+        {
+            self::init_link();
+            if (self::$trans_layers === 0) {
+                $ret = self::$link[$host]->autocommit(false);
+                Log::record("transaction begin ret=$ret", Log::DEBUG);
+            } else {
+                $ret = true;
+            }
 
-        if (self::$trans_layers === 0) {
-            self::$link[$host]->autocommit(false);
-            Log::record("transaction begin",Log::DEBUG);
+            if($ret === false)
+            {
+                self::closeLink($host);
+                $count += 1;
+                if($count > 1) {
+                    throw_exception("Mysql auto commit ERROR");
+                }
+            }
+            else {
+                break;
+            }
         }
+
         self::$trans_layers += 1;
     }
 

+ 2 - 2
data/config/dev/base.ini.php

@@ -53,14 +53,14 @@ define('SSH_TUNEL_PROD','local');
 
 if(SSH_TUNEL_PROD ==='local') {
     $config['db'][1]['dbhost']       = MASTER_DBHOST;
-    $config['db'][1]['dbport']       = '3307';
+    $config['db'][1]['dbport']       = '3306';
     $config['db'][1]['dbuser']       = 'root';
     $config['db'][1]['dbpwd']        = '55668899';
     $config['db'][1]['dbname']       = 'ylshop';
     $config['db'][1]['dbcharset']    = 'UTF-8';
 
     $config['db']['slave'][0]['dbhost']     = SLAVE_DBHOST;
-    $config['db']['slave'][0]['dbport']     = '3307';
+    $config['db']['slave'][0]['dbport']     = '3306';
     $config['db']['slave'][0]['dbuser']     = 'root';
     $config['db']['slave'][0]['dbpwd']      = '55668899';
     $config['db']['slave'][0]['dbname']     = 'ylshop';

+ 32 - 0
mobile/control/mtest.php

@@ -0,0 +1,32 @@
+<?php
+
+defined('InShopNC') or exit('Access Invalid!');
+
+define('MOBILE_SERVER',true);
+
+class mtestControl extends mobileControl
+{
+    public function sqlOp()
+    {
+        $mod_detail = Model('refill_detail');
+        $mod_detail->getDetailInfo(['detail_id' => 1]);
+        return $this->outsuccess([]);
+    }
+
+    public function transOp()
+    {
+        try {
+            $mod_detail = Model('refill_detail');
+            $trans = new trans_wapper($mod_detail,__METHOD__);
+//            $mod_detail->getDetailInfo(['detail_id' => 1]);
+            $trans->commit();
+
+        }
+        catch (Exception $ex)
+        {
+            $trans->rollback();
+        }
+
+        return $this->outsuccess([]);
+    }
+}