{"id":199592,"date":"2025-05-03T10:49:18","date_gmt":"2025-05-03T02:49:18","guid":{"rendered":"https:\/\/server.hk\/cnblog\/199592\/"},"modified":"2025-05-03T10:49:18","modified_gmt":"2025-05-03T02:49:18","slug":"%e6%94%b9%e9%80%a0ecshop%e8%af%bb%e5%86%99%e5%88%86%e7%a6%bb%e9%85%8d%e7%bd%ae%e4%b8%8e%e6%94%b9%e9%80%a0","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/199592\/","title":{"rendered":"\u6539\u9020ecshop\u8bfb\u5199\u5206\u79bb\u914d\u7f6e\u4e0e\u6539\u9020"},"content":{"rendered":"<p> \u524d\u4e24\u5929\u914d\u7f6e\u597d\u4e86mysql\u4e3b\u4ece\u65b9\u5f0f\uff0c\u4eca\u5929\u5c31\u62ffecshop\u7ec3\u4e60\u8bfb\u5199\u5206\u79bb\u3002\u4ee5\u4e0b\u4ee3\u7801\u4ec5\u4f9b\u5b66\u4e60\u53c2\u8003\uff0c\u4e0d\u6210\u719f\u7684\u5730\u65b9\uff0c\u8fd8\u9700\u5b8c\u5584\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.ldhost.cn\/helphmb\/uploads\/allimg\/170116\/1H55LV8-0.gif\" class=\"aligncenter\">  <\/p>\n<pre>\r\n&lt;?php\r\n\r\n$db_name   = \"ecshop\";\r\n\r\n$prefix    = \"ecs_\";\r\n\r\n$timezone    = \"Europe\/Berlin\";\r\n\r\n$cookie_path    = \"\/\";\r\n\r\n$cookie_domain    = \"\";\r\n\r\n$session = \"1440\";\r\n\r\n$_config = array();\r\n\r\n\/\/\u6570\u636e\u5e93\u4e3b\u670d\u52a1\u5668\u8bbe\u7f6e, \u652f\u6301\u591a\u7ec4\u670d\u52a1\u5668\u8bbe\u7f6e, \u5f53\u8bbe\u7f6e\u591a\u7ec4\u670d\u52a1\u5668\u65f6, \u5219\u4f1a\u968f\u673a\u4f7f\u7528\u67d0\u4e2a\u670d\u52a1\u5668\r\n$_config['master'][1]['dbhost'] = \"192.168.2.175:3306\";\r\n$_config['master'][1]['dbname'] = \"ecshop\";\r\n$_config['master'][1]['dbuser'] = \"dragon\";\r\n$_config['master'][1]['dbpw'] = \"loong\";\r\n\r\n\/*\r\n *$_config['master'][2]['dbhost'] = \"\";\r\n *...\r\n *\/\r\n\r\n\/\/\u6570\u636e\u5e93\u4ece\u670d\u52a1\u5668\u8bbe\u7f6e( slave, \u53ea\u8bfb ), \u652f\u6301\u591a\u7ec4\u670d\u52a1\u5668\u8bbe\u7f6e, \u5f53\u8bbe\u7f6e\u591a\u7ec4\u670d\u52a1\u5668\u65f6, \u7cfb\u7edf\u6bcf\u6b21\u968f\u673a\u4f7f\u7528\r\n$_config['slave'][1]['dbhost'] = \"192.168.2.176:3306\";\r\n$_config['slave'][1]['dbname'] = \"ecshop\";\r\n$_config['slave'][1]['dbuser'] = \"ivan\";\r\n$_config['slave'][1]['dbpw'] = \"loong\";\r\n\r\n$_config['slave'][2]['dbhost'] = \"192.168.2.177:3306\";\r\n$_config['slave'][2]['dbname'] = \"ecshop\";\r\n$_config['slave'][2]['dbuser'] = \"ivan\";\r\n$_config['slave'][2]['dbpw'] = \"loong\";\r\n\r\ndefine('EC_CHARSET','utf-8');\r\n\r\ndefine('ADMIN_PATH','admin');\r\n\r\ndefine('AUTH_KEY', 'this is a key');\r\n\r\ndefine('OLD_AUTH_KEY', '');\r\n\r\ndefine('API_TIME', '');\r\n\r\n?&gt;<\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/www.ldhost.cn\/helphmb\/uploads\/allimg\/170116\/1H55LV8-0.gif\" class=\"aligncenter\">   <\/p>\n<p> \u521d\u59cb\u5316\u6570\u636e\u8fde\u63a5\u7c7b<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.ldhost.cn\/helphmb\/uploads\/allimg\/170116\/1H55LV8-0.gif\" class=\"aligncenter\">  <\/p>\n<pre>\r\n    \/* \u521d\u59cb\u5316\u6570\u636e\u5e93\u7c7b   \r\n     * \u5982\u679c\u914d\u7f6e\u4e86\u4ece\u670d\u52a1\u5668\uff0c\u5219\u521d\u59cb\u5316\u4ece\u5e93\u7c7b  \r\n    *\/    \r\n    if(count($_config['slave'])) {    \r\n        require(ROOT_PATH . 'includes\/cls_mysql_slave.php');    \r\n        $db = new cls_mysql_slave($_config);    \r\n    }else{    \r\n        require(ROOT_PATH . 'includes\/cls_mysql.php');    \r\n        $db = new cls_mysql($_config);    \r\n    }    <\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/www.ldhost.cn\/helphmb\/uploads\/allimg\/170116\/1H55LV8-0.gif\" class=\"aligncenter\">   <\/p>\n<p> \u589e\u52a0cls_mysql_slave.php\u4ece\u5e93\u7c7b<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.ldhost.cn\/helphmb\/uploads\/allimg\/170116\/1H55LV8-0.gif\" class=\"aligncenter\">  <\/p>\n<pre>\r\n    &lt;?php  \r\n      \r\n    require(ROOT_PATH . 'includes\/cls_mysql.php');  \r\n    class cls_mysql_slave extends cls_mysql  \r\n    {  \r\n        var $slaveid = null;  \r\n      \r\n        function set_config($config){  \r\n            if(!empty($this-&gt;config['slave'])) {  \r\n                $this-&gt;slaveid = array_rand($this-&gt;config['slave']);  \r\n            }  \r\n            parent::set_config($config);  \r\n        }  \r\n      \r\n        \/* \u968f\u673a\u5206\u914d\u4ece\u5e93\u8fde\u63a5 *\/  \r\n        function set_slave_config() {           \r\n            $this-&gt;settings = $this-&gt;config['slave'][$this-&gt;slaveid];  \r\n            $this-&gt;settings['charset'] = $this-&gt;config['charset'];  \r\n            $this-&gt;settings['pconnect'] = $this-&gt;config['pconnect'];  \r\n        }  \r\n      \r\n        function slave_connect() {  \r\n            $this-&gt;set_slave_config();  \r\n            $dbhost = $this-&gt;settings['dbhost'];  \r\n            $dbuser = $this-&gt;settings['dbuser'];  \r\n            $dbpw = $this-&gt;settings['dbpw'];  \r\n            $dbname = $this-&gt;settings['dbname'];  \r\n            $this-&gt;connect($dbhost, $dbuser, $dbpw, $dbname);  \r\n              \r\n        }  \r\n      \r\n      \r\n        function query($sql, $type = '') {  \r\n            \/\/ \u5982\u679c\u6267\u884c\u67e5\u8be2\u64cd\u4f5c\uff0c\u5219\u6267\u884c\u4ece\u5e93\u8fde\u63a5  \r\n            if($this-&gt;slaveid &amp;&amp; strtoupper(substr($sql, 0 , 6)) == 'SELECT') {  \r\n                $this-&gt;slave_connect();  \r\n            }else{  \r\n                parent::set_config($this-&gt;config);  \r\n                $dbhost = $this-&gt;settings['dbhost'];  \r\n                $dbuser = $this-&gt;settings['dbuser'];  \r\n                $dbpw = $this-&gt;settings['dbpw'];  \r\n                $dbname = $this-&gt;settings['dbname'];  \r\n                $this-&gt;connect($dbhost, $dbuser, $dbpw, $dbname);  \r\n            }  \r\n            return parent::query($sql, $type);  \r\n        }  \r\n      \r\n        \/* \u5220\u9664\u5931\u8d25\u8fde\u63a5*\/  \r\n        function del_error_link(){  \r\n            unset($this-&gt;config['slave'][$this-&gt;slaveid]);  \r\n            $this-&gt;set_config($this-&gt;config);  \r\n            $this-&gt;set_slave_config();  \r\n            $dbhost = $this-&gt;settings['dbhost'];  \r\n            $dbuser = $this-&gt;settings['dbuser'];  \r\n            $dbpw = $this-&gt;settings['dbpw'];  \r\n            $dbname = $this-&gt;settings['dbname'];  \r\n            $this-&gt;connect($dbhost, $dbuser, $dbpw, $dbname);  \r\n        }  \r\n               \r\n    }  <\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/www.ldhost.cn\/helphmb\/uploads\/allimg\/170116\/1H55LV8-0.gif\" class=\"aligncenter\">   <\/p>\n<p> cls_mysql.php\u6587\u4ef6\u7c7b\u4fee\u6539<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.ldhost.cn\/helphmb\/uploads\/allimg\/170116\/1H55LV8-0.gif\" class=\"aligncenter\">  <\/p>\n<pre>\r\n    &lt;?php  \r\n      \r\n    if (!defined('IN_ECS'))  \r\n    {  \r\n        die('Hacking attempt');  \r\n    }  \r\n      \r\n    class cls_mysql  \r\n    {  \r\n        var $link_id    = NULL;  \r\n      \r\n        var $settings   = array();  \r\n      \r\n        var $queryCount = 0;  \r\n        var $linkCount = 0;  \r\n        var $queryTime  = '';  \r\n        var $queryLog   = array();  \r\n      \r\n        var $max_cache_time = 300; \/\/ \u6700\u5927\u7684\u7f13\u5b58\u65f6\u95f4\uff0c\u4ee5\u79d2\u4e3a\u5355\u4f4d  \r\n      \r\n        var $cache_data_dir = 'temp\/query_caches\/';  \r\n        var $root_path      = '';  \r\n      \r\n        var $error_message  = array();  \r\n        var $platform       = '';  \r\n        var $version        = '';  \r\n        var $dbhash         = '';  \r\n        var $starttime      = 0;  \r\n        var $timeline       = 0;  \r\n        var $timezone       = 0;  \r\n      \r\n        var $mysql_config_cache_file_time = 0;  \r\n      \r\n        var $mysql_disable_cache_tables = array(); \/\/ \u4e0d\u5141\u8bb8\u88ab\u7f13\u5b58\u7684\u8868\uff0c\u9047\u5230\u5c06\u4e0d\u4f1a\u8fdb\u884c\u7f13\u5b58  \r\n        var $config = array();  \r\n      \r\n        function __construct($config, $charset = 'utf8', $pconnect = 0, $quiet = 0)  \r\n        {  \r\n            $this-&gt;cls_mysql($config, $charset, $pconnect, $quiet);  \r\n        }  \r\n      \r\n        function cls_mysql($config, $charset = 'utf8', $pconnect = 0, $quiet = 0)  \r\n        {  \r\n            if(!empty($config)) {  \r\n                $config['charset'] = $charset;  \r\n                $config['pconnect'] = $pconnect;  \r\n                $this-&gt;config = $config;  \r\n            }  \r\n              \r\n            if (defined('EC_CHARSET'))  \r\n            {  \r\n                $charset = strtolower(str_replace('-', '', EC_CHARSET));  \r\n            }  \r\n      \r\n            if (defined('ROOT_PATH') &amp;&amp; !$this-&gt;root_path)  \r\n            {  \r\n                $this-&gt;root_path = ROOT_PATH;  \r\n            }  \r\n      \r\n            $this-&gt;set_config($this-&gt;config);  \r\n      \r\n            if ($quiet)  \r\n            {  \r\n                $dbhost = $this-&gt;settings['dbhost'];  \r\n                $dbuser = $this-&gt;settings['dbuser'];  \r\n                $dbpw = $this-&gt;settings['dbpw'];  \r\n                $dbname = $this-&gt;settings['dbname'];  \r\n                $this-&gt;connect($dbhost, $dbuser, $dbpw, $dbname, $charset, $pconnect, $quiet);  \r\n            }  \r\n        }  \r\n      \r\n        \/\/\u968f\u673a\u5206\u914d\u6570\u636e\u5e93\u8fde\u63a5  \r\n        function set_config($config) {  \r\n            $sid = array_rand($config['master']);  \r\n            $settings = $config['master'][$sid];  \r\n            $settings['sid'] = $sid;  \r\n            $settings['charset'] = $this-&gt;config['charset'];  \r\n            $settings['pconnect'] = $this-&gt;config['pconnect'];  \r\n            $this-&gt;settings = $settings;  \r\n        }  \r\n      \r\n        function connect($dbhost, $dbuser, $dbpw, $dbname = '', $charset = 'utf8', $pconnect = 0, $quiet = 0)  \r\n        {  \r\n            if ($pconnect)  \r\n            {  \r\n                if (!($this-&gt;link_id = @mysql_pconnect($dbhost, $dbuser, $dbpw)))  \r\n                {  \r\n                    if (!$quiet)  \r\n                    {  \r\n                        $this-&gt;ErrorMsg(\"Can't pConnect MySQL Server!\");  \r\n                    }  \r\n      \r\n                    return false;  \r\n                }  \r\n            }  \r\n            else  \r\n            {  \r\n                if (PHP_VERSION &gt;= '4.2')  \r\n                {  \r\n                    $this-&gt;link_id = @mysql_connect($dbhost, $dbuser, $dbpw, true);  \r\n                }  \r\n                else  \r\n                {  \r\n                    $this-&gt;link_id = @mysql_connect($dbhost, $dbuser, $dbpw);  \r\n      \r\n                    mt_srand((double)microtime() * 1000000); \/\/ \u5bf9 PHP 4.2 \u4ee5\u4e0b\u7684\u7248\u672c\u8fdb\u884c\u968f\u673a\u6570\u51fd\u6570\u7684\u521d\u59cb\u5316\u5de5\u4f5c  \r\n                }  \r\n                if (!$this-&gt;link_id)  \r\n                {  \r\n                    if (!$quiet)  \r\n                    {                    \r\n                        \/\/\u8fde\u63a5\u8d85\u8fc710\u6b21\uff0c\u4e2d\u65ad\u8fde\u63a5\uff0c\u629b\u51fa\u9519\u8bef    \r\n                        if($this-&gt;linkCount&gt;9){  \r\n                            $this-&gt;ErrorMsg(\"Can't Connect MySQL Server!\");  \r\n                        }   \r\n                        $this-&gt;linkCount++;  \r\n                        $this-&gt;del_error_link();  \r\n                    }  \r\n      \r\n                    return false;  \r\n                }  \r\n            }  \r\n      \r\n            $this-&gt;dbhash  = md5($this-&gt;root_path . $dbhost . $dbuser . $dbpw . $dbname);  \r\n            $this-&gt;version = mysql_get_server_info($this-&gt;link_id);  \r\n      \r\n            \/* \u5982\u679cmysql \u7248\u672c\u662f 4.1+ \u4ee5\u4e0a\uff0c\u9700\u8981\u5bf9\u5b57\u7b26\u96c6\u8fdb\u884c\u521d\u59cb\u5316 *\/  \r\n            if ($this-&gt;version &gt; '4.1')  \r\n            {  \r\n                if ($charset != 'latin1')  \r\n                {  \r\n                    mysql_query(\"SET character_set_connection=$charset, character_set_results=$charset, character_set_client=binary\", $this-&gt;link_id);  \r\n                }  \r\n                if ($this-&gt;version &gt; '5.0.1')  \r\n                {  \r\n                    mysql_query(\"SET sql_mode=''\", $this-&gt;link_id);  \r\n                }  \r\n            }  \r\n      \r\n            $sqlcache_config_file = $this-&gt;root_path . $this-&gt;cache_data_dir . 'sqlcache_config_file_' . $this-&gt;dbhash . '.php';  \r\n      \r\n            @include($sqlcache_config_file);  \r\n      \r\n            $this-&gt;starttime = time();  \r\n      \r\n            if ($this-&gt;max_cache_time &amp;&amp; $this-&gt;starttime &gt; $this-&gt;mysql_config_cache_file_time + $this-&gt;max_cache_time)  \r\n            {  \r\n                if ($dbhost != '.')  \r\n                {  \r\n                    $result = mysql_query(\"SHOW VARIABLES LIKE 'basedir'\", $this-&gt;link_id);  \r\n                    $row    = mysql_fetch_assoc($result);  \r\n                    if (!empty($row['Value']{1}) &amp;&amp; $row['Value']{1} == ':' &amp;&amp; !empty($row['Value']{2}) &amp;&amp; $row['Value']{2} == \"\\\\\")  \r\n                    {  \r\n                        $this-&gt;platform = 'WINDOWS';  \r\n                    }  \r\n                    else  \r\n                    {  \r\n                        $this-&gt;platform = 'OTHER';  \r\n                    }  \r\n                }  \r\n                else  \r\n                {  \r\n                    $this-&gt;platform = 'WINDOWS';  \r\n                }  \r\n      \r\n                if ($this-&gt;platform == 'OTHER' &amp;&amp;  \r\n                    ($dbhost != '.' &amp;&amp; strtolower($dbhost) != 'localhost:3306' &amp;&amp; $dbhost != '127.0.0.1:3306') ||  \r\n                    (PHP_VERSION &gt;= '5.1' &amp;&amp; date_default_timezone_get() == 'UTC'))  \r\n                {  \r\n                    $result = mysql_query(\"SELECT UNIX_TIMESTAMP() AS timeline, UNIX_TIMESTAMP('\" . date('Y-m-d H:i:s', $this-&gt;starttime) . \"') AS timezone\", $this-&gt;link_id);  \r\n                    $row    = mysql_fetch_assoc($result);  \r\n      \r\n                    if ($dbhost != '.' &amp;&amp; strtolower($dbhost) != 'localhost:3306' &amp;&amp; $dbhost != '127.0.0.1:3306')  \r\n                    {  \r\n                        $this-&gt;timeline = $this-&gt;starttime - $row['timeline'];  \r\n                    }  \r\n      \r\n                    if (PHP_VERSION &gt;= '5.1' &amp;&amp; date_default_timezone_get() == 'UTC')  \r\n                    {  \r\n                        $this-&gt;timezone = $this-&gt;starttime - $row['timezone'];  \r\n                    }  \r\n                }  \r\n      \r\n                $content = '&lt;' . \"?php\\r\\n\" .  \r\n                           '$this-&gt;mysql_config_cache_file_time = ' . $this-&gt;starttime . \";\\r\\n\" .  \r\n                           '$this-&gt;timeline = ' . $this-&gt;timeline . \";\\r\\n\" .  \r\n                           '$this-&gt;timezone = ' . $this-&gt;timezone . \";\\r\\n\" .  \r\n                           '$this-&gt;platform = ' . \"'\" . $this-&gt;platform . \"';\\r\\n?\" . '&gt;';  \r\n      \r\n                @file_put_contents($sqlcache_config_file, $content);  \r\n            }  \r\n      \r\n            \/* \u9009\u62e9\u6570\u636e\u5e93 *\/  \r\n            if ($dbname)  \r\n            {  \r\n                if (mysql_select_db($dbname, $this-&gt;link_id) === false )  \r\n                {  \r\n                    if (!$quiet)  \r\n                    {  \r\n                        $this-&gt;ErrorMsg(\"Can't select MySQL database!\");  \r\n                    }  \r\n      \r\n                    return false;  \r\n                }  \r\n                else  \r\n                {  \r\n                    return true;  \r\n                }  \r\n            }  \r\n            else  \r\n            {  \r\n                return true;  \r\n            }  \r\n        }  \r\n      \r\n        ......  \r\n      \r\n        \/* \u5220\u9664\u5931\u8d25\u8fde\u63a5*\/  \r\n        function del_error_link(){  \r\n            unset($this-&gt;config['master'][$this-&gt;settings['sid']]);  \r\n            $this-&gt;set_config($this-&gt;config);  \r\n            $dbhost = $this-&gt;settings['dbhost'];  \r\n            $dbuser = $this-&gt;settings['dbuser'];  \r\n            $dbpw = $this-&gt;settings['dbpw'];  \r\n            $dbname = $this-&gt;settings['dbname'];  \r\n            $this-&gt;connect($dbhost, $dbuser, $dbpw, $dbname);  \r\n        }  \r\n    }  <\/pre>\n<p> <\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u4e24\u5929\u914d\u7f6e\u597d\u4e86mysql\u4e3b\u4ece\u65b9\u5f0f&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-199592","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/199592","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=199592"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/199592\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=199592"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=199592"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=199592"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}