UpdateController.class.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  1. <?php
  2. namespace Home\Controller;
  3. use Think\Controller;
  4. class UpdateController extends BaseController {
  5. //升级数据库
  6. public function db(){
  7. $this->_clear_runtime();
  8. if (strtolower(C("DB_TYPE")) == 'mysql' ) {
  9. //$this->mysql();
  10. echo 'ShowDoc does not support mysql any more . https://www.showdoc.cc/help?page_id=31990 ';
  11. }
  12. elseif (strtolower(C("DB_TYPE")) == 'sqlite' ) {
  13. $this->sqlite();
  14. }
  15. $this->_clear_runtime();
  16. }
  17. public function sqlite(){
  18. //catalog表增加parent_cat_id字段
  19. if (!$this->_is_column_exist("catalog","parent_cat_id")) {
  20. $sql = "ALTER TABLE ".C('DB_PREFIX')."catalog ADD parent_cat_id INT( 10 ) NOT NULL DEFAULT '0' ;";
  21. D("catalog")->execute($sql);
  22. }
  23. //catalog表增加level字段
  24. if (!$this->_is_column_exist("catalog","level")) {
  25. $sql = "ALTER TABLE ".C('DB_PREFIX')."catalog ADD level INT( 10 ) NOT NULL DEFAULT '2' ;";
  26. D("catalog")->execute($sql);
  27. }
  28. //item表增加item_domain字段
  29. if (!$this->_is_column_exist("item","item_domain")) {
  30. $sql = "ALTER TABLE ".C('DB_PREFIX')."item ADD item_domain text NOT NULL DEFAULT '';";
  31. D("catalog")->execute($sql);
  32. }
  33. //创建user_token表
  34. $sql = "CREATE TABLE IF NOT EXISTS `user_token` (
  35. `id` INTEGER PRIMARY KEY ,
  36. `uid` int(10) NOT NULL DEFAULT '0',
  37. `token` CHAR(200) NOT NULL DEFAULT '',
  38. `token_expire` int(11) NOT NULL DEFAULT '0' ,
  39. `ip` CHAR(200) NOT NULL DEFAULT '',
  40. `addtime` int(11) NOT NULL DEFAULT '0'
  41. )";
  42. D("UserToken")->execute($sql);
  43. //创建template表
  44. $sql = "CREATE TABLE IF NOT EXISTS `template` (
  45. `id` INTEGER PRIMARY KEY ,
  46. `uid` int(10) NOT NULL DEFAULT '0',
  47. `username` CHAR(200) NOT NULL DEFAULT '',
  48. `template_title` CHAR(200) NOT NULL DEFAULT '' ,
  49. `template_content` text NOT NULL DEFAULT '',
  50. `addtime` int(11) NOT NULL DEFAULT '0'
  51. )";
  52. D("UserToken")->execute($sql);
  53. //page表增加page_comments字段
  54. if (!$this->_is_column_exist("page","page_comments")) {
  55. $sql = "ALTER TABLE ".C('DB_PREFIX')."page ADD page_comments text NOT NULL DEFAULT '' ;";
  56. D("catalog")->execute($sql);
  57. }
  58. //page_history 表增加page_comments字段
  59. if (!$this->_is_column_exist("PageHistory","page_comments")) {
  60. $sql = "ALTER TABLE ".C('DB_PREFIX')."page_history ADD page_comments text NOT NULL DEFAULT '';";
  61. D("catalog")->execute($sql);
  62. }
  63. //item_member表增加member_group_id字段
  64. if (!$this->_is_column_exist("ItemMember","member_group_id")) {
  65. $sql = "ALTER TABLE ".C('DB_PREFIX')."item_member ADD member_group_id INT( 1 ) NOT NULL DEFAULT '1' ;";
  66. D("ItemMember")->execute($sql);
  67. }
  68. //item表增加item_type字段
  69. if (!$this->_is_column_exist("Item","item_type")) {
  70. $sql = "ALTER TABLE ".C('DB_PREFIX')."item ADD item_type INT( 1 ) NOT NULL DEFAULT '1' ;";
  71. D("ItemMember")->execute($sql);
  72. }
  73. //创建options表
  74. $sql = "CREATE TABLE IF NOT EXISTS `options` (
  75. `option_id` INTEGER PRIMARY KEY ,
  76. `option_name` CHAR(200) NOT NULL UNIQUE ,
  77. `option_value` CHAR(200) NOT NULL
  78. )";
  79. D("UserToken")->execute($sql);
  80. //创建item_token表
  81. $sql = "CREATE TABLE IF NOT EXISTS `item_token` (
  82. `id` INTEGER PRIMARY KEY ,
  83. `item_id` int(11) NOT NULL DEFAULT '0' ,
  84. `api_key` CHAR(200) NOT NULL UNIQUE ,
  85. `api_token` CHAR(200) NOT NULL ,
  86. `addtime` int(11) NOT NULL DEFAULT '0' ,
  87. `last_check_time` int(11) NOT NULL DEFAULT '0'
  88. )";
  89. D("UserToken")->execute($sql);
  90. //创建item_top表
  91. $sql = "CREATE TABLE IF NOT EXISTS `item_top` (
  92. `id` INTEGER PRIMARY KEY ,
  93. `item_id` int(11) NOT NULL DEFAULT '0' ,
  94. `uid` int(11) NOT NULL DEFAULT '0' ,
  95. `addtime` int(11) NOT NULL DEFAULT '0'
  96. )";
  97. D("UserToken")->execute($sql);
  98. //item表增加is_archived字段
  99. if (!$this->_is_column_exist("Item","is_archived")) {
  100. $sql = "ALTER TABLE ".C('DB_PREFIX')."item ADD is_archived INT( 1 ) NOT NULL DEFAULT '0' ;";
  101. D("ItemMember")->execute($sql);
  102. }
  103. //管理员账户和权限
  104. if(D("User")->where("username = 'showdoc' ")->find()){
  105. D("User")->where("username = 'showdoc' ")->save(array("groupid"=> 1)) ;
  106. }else{
  107. D("User")->add(array('username'=>"showdoc" ,"groupid"=>1,'password'=>"a89da13684490eb9ec9e613f91d24d00" , 'reg_time'=>time()));
  108. }
  109. //item表增加is_del字段
  110. if (!$this->_is_column_exist("Item","is_del")) {
  111. $sql = "ALTER TABLE ".C('DB_PREFIX')."item ADD is_del INT( 1 ) NOT NULL DEFAULT '0' ;";
  112. D("ItemMember")->execute($sql);
  113. }
  114. //page表增加is_del字段
  115. if (!$this->_is_column_exist("Page","is_del")) {
  116. $sql = "ALTER TABLE ".C('DB_PREFIX')."page ADD is_del INT( 1 ) NOT NULL DEFAULT '0' ;";
  117. D("ItemMember")->execute($sql);
  118. }
  119. //创建team表
  120. $sql = "CREATE TABLE IF NOT EXISTS `team` (
  121. `id` INTEGER PRIMARY KEY ,
  122. `team_name` CHAR(200) NOT NULL DEFAULT '',
  123. `uid` int(11) NOT NULL DEFAULT '0' ,
  124. `username` CHAR(200) NOT NULL DEFAULT '',
  125. `addtime` int(11) NOT NULL DEFAULT '0' ,
  126. `last_update_time` int(11) NOT NULL DEFAULT '0'
  127. )";
  128. D("User")->execute($sql);
  129. //创建team_item表
  130. $sql = "CREATE TABLE IF NOT EXISTS `team_item` (
  131. `id` INTEGER PRIMARY KEY ,
  132. `team_id` int(11) NOT NULL DEFAULT '0' ,
  133. `item_id` int(11) NOT NULL DEFAULT '0' ,
  134. `addtime` int(11) NOT NULL DEFAULT '0' ,
  135. `last_update_time` int(11) NOT NULL DEFAULT '0'
  136. )";
  137. D("User")->execute($sql);
  138. //创建team_item_member表
  139. $sql = "CREATE TABLE IF NOT EXISTS `team_item_member` (
  140. `id` INTEGER PRIMARY KEY ,
  141. `team_id` int(11) NOT NULL DEFAULT '0' ,
  142. `item_id` int(11) NOT NULL DEFAULT '0' ,
  143. `member_group_id` int(11) NOT NULL DEFAULT '0' ,
  144. `member_uid` int(11) NOT NULL DEFAULT '0' ,
  145. `member_username` CHAR(200) NOT NULL DEFAULT '',
  146. `addtime` int(11) NOT NULL DEFAULT '0' ,
  147. `last_update_time` int(11) NOT NULL DEFAULT '0'
  148. )";
  149. D("User")->execute($sql);
  150. //创建team_member表
  151. $sql = "CREATE TABLE IF NOT EXISTS `team_member` (
  152. `id` INTEGER PRIMARY KEY ,
  153. `team_id` int(11) NOT NULL DEFAULT '0' ,
  154. `member_uid` int(11) NOT NULL DEFAULT '0' ,
  155. `member_username` CHAR(200) NOT NULL DEFAULT '',
  156. `addtime` int(11) NOT NULL DEFAULT '0' ,
  157. `last_update_time` int(11) NOT NULL DEFAULT '0'
  158. )";
  159. D("User")->execute($sql);
  160. //创建upload_file表
  161. $sql = "CREATE TABLE IF NOT EXISTS `upload_file` (
  162. `file_id` INTEGER PRIMARY KEY ,
  163. `sign` CHAR(200) NOT NULL DEFAULT '',
  164. `display_name` CHAR(200) NOT NULL DEFAULT '',
  165. `file_type` CHAR(200) NOT NULL DEFAULT '',
  166. `file_size` CHAR(200) NOT NULL DEFAULT '',
  167. `uid` int(11) NOT NULL DEFAULT '0' ,
  168. `page_id` int(11) NOT NULL DEFAULT '0' ,
  169. `item_id` int(11) NOT NULL DEFAULT '0' ,
  170. `visit_times` int(11) NOT NULL DEFAULT '0' ,
  171. `addtime` int(11) NOT NULL DEFAULT '0' ,
  172. `real_url` CHAR(200) NOT NULL DEFAULT '',
  173. `last_update_time` int(11) NOT NULL DEFAULT '0'
  174. )";
  175. D("User")->execute($sql);
  176. //创建item_sort表
  177. $sql = "CREATE TABLE IF NOT EXISTS `item_sort` (
  178. `id` INTEGER PRIMARY KEY ,
  179. `uid` int(10) NOT NULL DEFAULT '0',
  180. `item_sort_data` text NOT NULL DEFAULT '',
  181. `addtime` int(11) NOT NULL DEFAULT '0'
  182. )";
  183. D("UserToken")->execute($sql);
  184. //创建single_page表
  185. $sql = "CREATE TABLE IF NOT EXISTS `single_page` (
  186. `id` INTEGER PRIMARY KEY ,
  187. `unique_key` CHAR(200) NOT NULL DEFAULT '',
  188. `page_id` int(11) NOT NULL DEFAULT '0'
  189. )";
  190. D("UserToken")->execute($sql);
  191. echo "OK!\n";
  192. }
  193. private function _is_column_exist($table , $column){
  194. $has_it = false ;//是否存在该字段
  195. $columns = M($table)->getDbFields();
  196. if ($columns) {
  197. foreach ($columns as $key => $value) {
  198. if ($value == $column) {
  199. $has_it = true ;
  200. }
  201. }
  202. }
  203. return $has_it ;
  204. }
  205. private function _clear_runtime($path = RUNTIME_PATH){
  206. //给定的目录不是一个文件夹
  207. if(!is_dir($path)){
  208. return null;
  209. }
  210. $fh = opendir($path);
  211. while(($row = readdir($fh)) !== false){
  212. //过滤掉虚拟目录
  213. if($row == '.' || $row == '..'|| $row == 'index.html'){
  214. continue;
  215. }
  216. if(!is_dir($path.'/'.$row)){
  217. unlink($path.'/'.$row);
  218. }
  219. $this->_clear_runtime($path.'/'.$row);
  220. }
  221. //关闭目录句柄,否则出Permission denied
  222. closedir($fh);
  223. return true;
  224. }
  225. //转移mysql的数据到sqlite
  226. public function toSqlite(){
  227. $this->_clear_runtime();
  228. if (strtolower(C("DB_TYPE")) == 'mysql' ) {
  229. $this->mysql();
  230. $this->_moveTable("catalog");
  231. $this->_moveTable("item");
  232. $this->_moveTable("item_member");
  233. $this->_moveTable("page");
  234. $this->_moveTable("page_history");
  235. $this->_moveTable("template");
  236. $this->_moveTable("user");
  237. $this->_moveTable("user_token");
  238. $db_config = array(
  239. 'DB_TYPE' => 'Sqlite',
  240. 'DB_NAME' => 'Sqlite/showdoc.db.php',
  241. );
  242. $array = M("item")->db(2,$db_config)->select();
  243. if ($array) {
  244. echo "ok";
  245. }else{
  246. echo 'fail';
  247. }
  248. }
  249. else{
  250. echo "mysql not found";
  251. }
  252. $this->_clear_runtime();
  253. }
  254. //升级mysql数据库
  255. public function mysql(){
  256. //user表的username字段增大了长度,防止长邮箱的用户名注册不了
  257. $sql = "alter table ".C('DB_PREFIX')."user modify column username varchar(50) CHARACTER SET utf8 NOT NULL DEFAULT '' ";
  258. M("Catalog")->execute($sql);
  259. //item表增加last_update_time字段
  260. $columns = M("item")->getDbFields();
  261. if ($columns) {
  262. $has_it = 0 ;//是否存在该字段
  263. foreach ($columns as $key => $value) {
  264. if ($value == 'last_update_time') {
  265. $has_it = 1 ;
  266. }
  267. }
  268. if ($has_it === 0) {
  269. $sql = "ALTER TABLE ".C('DB_PREFIX')."item ADD last_update_time INT( 11 ) NOT NULL DEFAULT '0' COMMENT '最后更新时间';";
  270. D("Item")->execute($sql);
  271. }
  272. }
  273. //更改catalog表的order字段名为s_number
  274. $columns = M("Catalog")->getDbFields();
  275. if ($columns) {
  276. foreach ($columns as $key => $value) {
  277. if ($value == 'order') {
  278. $sql = "ALTER TABLE `".C('DB_PREFIX')."catalog` CHANGE `order` `s_number` INT( 10 ) NOT NULL DEFAULT '99' COMMENT '顺序号。数字越小越靠前。若此值全部相等时则按id排序';";
  279. M("Catalog")->execute($sql);
  280. }
  281. }
  282. }
  283. //更改page表的order字段名为s_number
  284. $columns = M("Page")->getDbFields();
  285. if ($columns) {
  286. foreach ($columns as $key => $value) {
  287. if ($value == 'order') {
  288. $sql = "ALTER TABLE `".C('DB_PREFIX')."page` CHANGE `order` `s_number` INT( 10 ) NOT NULL DEFAULT '99' COMMENT '顺序号。数字越小越靠前。若此值全部相等时则按id排序';";
  289. M("Page")->execute($sql);
  290. }
  291. }
  292. }
  293. //更改page_history表的order字段名为s_number
  294. $columns = M("PageHistory")->getDbFields();
  295. if ($columns) {
  296. foreach ($columns as $key => $value) {
  297. if ($value == 'order') {
  298. $sql = "ALTER TABLE `".C('DB_PREFIX')."page_history` CHANGE `order` `s_number` INT( 10 ) NOT NULL DEFAULT '99' COMMENT '顺序号。数字越小越靠前。若此值全部相等时则按id排序';";
  299. M("PageHistory")->execute($sql);
  300. }
  301. }
  302. }
  303. //为catalog表增加addtime索引
  304. $indexs = M("Catalog")->query(" show index from ".C('DB_PREFIX')."catalog");
  305. if ($indexs) {
  306. $has_it = 0 ;//是否存在该索引
  307. foreach ($indexs as $key => $value) {
  308. if ($value['column_name'] =='addtime') {
  309. $has_it = 1 ;
  310. }
  311. }
  312. if ($has_it === 0 ) {
  313. M("Catalog")->execute("ALTER TABLE ".C('DB_PREFIX')."catalog ADD INDEX ( `addtime` ) ;");
  314. }
  315. }
  316. //为item表增加addtime索引
  317. $indexs = M("Item")->query(" show index from ".C('DB_PREFIX')."item");
  318. if ($indexs) {
  319. $has_it = 0 ;//是否存在该索引
  320. foreach ($indexs as $key => $value) {
  321. if ($value['column_name'] =='addtime') {
  322. $has_it = 1 ;
  323. }
  324. }
  325. if ($has_it === 0 ) {
  326. M("Item")->execute("ALTER TABLE ".C('DB_PREFIX')."item ADD INDEX ( `addtime` ) ;");
  327. }
  328. }
  329. //为page表增加addtime索引
  330. $indexs = M("Page")->query(" show index from ".C('DB_PREFIX')."page");
  331. if ($indexs) {
  332. $has_it = 0 ;//是否存在该索引
  333. foreach ($indexs as $key => $value) {
  334. if ($value['column_name'] =='addtime') {
  335. $has_it = 1 ;
  336. }
  337. }
  338. if ($has_it === 0 ) {
  339. M("page")->execute("ALTER TABLE ".C('DB_PREFIX')."page ADD INDEX ( `addtime` ) ;");
  340. }
  341. }
  342. //为page_history表增加addtime索引
  343. $indexs = M("PageHistory")->query(" show index from ".C('DB_PREFIX')."page_history");
  344. if ($indexs) {
  345. $has_it = 0 ;//是否存在该索引
  346. foreach ($indexs as $key => $value) {
  347. if ($value['column_name'] =='addtime') {
  348. $has_it = 1 ;
  349. }
  350. }
  351. if ($has_it === 0 ) {
  352. M("PageHistory")->execute("ALTER TABLE ".C('DB_PREFIX')."page_history ADD INDEX ( `addtime` ) ;");
  353. }
  354. }
  355. //为page_history表增加page_id索引
  356. $indexs = M("PageHistory")->query(" show index from ".C('DB_PREFIX')."page_history");
  357. if ($indexs) {
  358. $has_it = 0 ;//是否存在该索引
  359. foreach ($indexs as $key => $value) {
  360. if ($value['column_name'] =='page_id') {
  361. $has_it = 1 ;
  362. }
  363. }
  364. if ($has_it === 0 ) {
  365. M("PageHistory")->execute("ALTER TABLE ".C('DB_PREFIX')."page_history ADD INDEX ( `page_id` ) ;");
  366. }
  367. }
  368. //catalog表增加parent_cat_id字段
  369. $columns = M("catalog")->getDbFields();
  370. if ($columns) {
  371. $has_it = 0 ;//是否存在该字段
  372. foreach ($columns as $key => $value) {
  373. if ($value == 'parent_cat_id') {
  374. $has_it = 1 ;
  375. }
  376. }
  377. if ($has_it === 0) {
  378. $sql = "ALTER TABLE ".C('DB_PREFIX')."catalog ADD parent_cat_id INT( 10 ) NOT NULL DEFAULT '0' COMMENT '上一级目录的id';";
  379. D("catalog")->execute($sql);
  380. }
  381. }
  382. //catalog表增加level字段
  383. $columns = M("catalog")->getDbFields();
  384. if ($columns) {
  385. $has_it = 0 ;//是否存在该字段
  386. foreach ($columns as $key => $value) {
  387. if ($value == 'level') {
  388. $has_it = 1 ;
  389. }
  390. }
  391. if ($has_it === 0) {
  392. $sql = "ALTER TABLE ".C('DB_PREFIX')."catalog ADD level INT( 10 ) NOT NULL DEFAULT '2' COMMENT '2为二级目录,3为三级目录';";
  393. D("catalog")->execute($sql);
  394. }
  395. }
  396. //item表增加item_domain字段
  397. $columns = M("item")->getDbFields();
  398. if ($columns) {
  399. $has_it = 0 ;//是否存在该字段
  400. foreach ($columns as $key => $value) {
  401. if ($value == 'item_domain') {
  402. $has_it = 1 ;
  403. }
  404. }
  405. if ($has_it === 0) {
  406. $sql = "ALTER TABLE ".C('DB_PREFIX')."item ADD item_domain varchar( 50 ) NOT NULL DEFAULT '' COMMENT 'item的个性域名';";
  407. D("item")->execute($sql);
  408. }
  409. }
  410. $sql = "CREATE TABLE IF NOT EXISTS `".C('DB_PREFIX')."user_token` (
  411. `id` int(10) NOT NULL AUTO_INCREMENT,
  412. `uid` int(10) NOT NULL DEFAULT '0',
  413. `token` varchar(200) NOT NULL DEFAULT '',
  414. `token_expire` int(11) NOT NULL DEFAULT '0' ,
  415. `ip` varchar(200) NOT NULL DEFAULT '',
  416. `addtime` int(11) NOT NULL DEFAULT '0',
  417. PRIMARY KEY (`id`),
  418. KEY `token` (`token`)
  419. ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='' AUTO_INCREMENT=1 ";
  420. D("User")->execute($sql);
  421. //创建template表
  422. $sql = "CREATE TABLE IF NOT EXISTS `".C('DB_PREFIX')."template` (
  423. `id` int(10) NOT NULL AUTO_INCREMENT,
  424. `uid` int(10) NOT NULL DEFAULT '0',
  425. `username` varchar(200) NOT NULL DEFAULT '',
  426. `template_title` varchar(200) NOT NULL DEFAULT '' ,
  427. `template_content` text NOT NULL ,
  428. `addtime` int(11) NOT NULL DEFAULT '0',
  429. PRIMARY KEY (`id`),
  430. KEY `uid` (`uid`)
  431. )ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='' AUTO_INCREMENT=1";
  432. D("UserToken")->execute($sql);
  433. //page表增加page_comments字段
  434. $columns = M("Page")->getDbFields();
  435. if ($columns) {
  436. $has_it = 0 ;//是否存在该字段
  437. foreach ($columns as $key => $value) {
  438. if ($value == 'page_comments') {
  439. $has_it = 1 ;
  440. }
  441. }
  442. if ($has_it === 0) {
  443. $sql = "ALTER TABLE ".C('DB_PREFIX')."page ADD page_comments varchar( 255 ) NOT NULL DEFAULT '' COMMENT '页面注释';";
  444. D("Page")->execute($sql);
  445. }
  446. }
  447. //page_history表增加page_comments字段
  448. $columns = M("PageHistory")->getDbFields();
  449. if ($columns) {
  450. $has_it = 0 ;//是否存在该字段
  451. foreach ($columns as $key => $value) {
  452. if ($value == 'page_comments') {
  453. $has_it = 1 ;
  454. }
  455. }
  456. if ($has_it === 0) {
  457. $sql = "ALTER TABLE ".C('DB_PREFIX')."page_history ADD page_comments varchar( 255 ) NOT NULL DEFAULT '' COMMENT '页面注释';";
  458. D("PageHistory")->execute($sql);
  459. }
  460. }
  461. if(D("User")->where("uid = 1 ")->find()){
  462. $db_config = array(
  463. 'DB_TYPE' => 'Sqlite',
  464. 'DB_NAME' => 'Sqlite/showdoc.db.php',
  465. );
  466. M("User")->db(2,$db_config)->where("uid = 1 ")->delete();
  467. }
  468. }
  469. private function _moveTable($table){
  470. $db_config = array(
  471. 'DB_TYPE' => 'Sqlite',
  472. 'DB_NAME' => 'Sqlite/showdoc.db.php',
  473. );
  474. $array = M($table)->select();
  475. if ($array) {
  476. foreach ($array as $key => $value) {
  477. M($table)->db(2,$db_config)->add($value);
  478. }
  479. }
  480. }
  481. }