chengkun
2025-05-26 8f3df543230cd4403368b39b9bbe5726d11a0284
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
<?php
 
 
class model {
    // 操作状态
    const MODEL_INSERT = 1;      //  插入模型数据
    const MODEL_UPDATE = 2;      //  更新模型数据
    const MODEL_BOTH = 3;      //  包含上面两种方式
    const MUST_VALIDATE = 1;      // 必须验证
    const EXISTS_VALIDATE = 0;      // 表单存在字段则验证
    const VALUE_VALIDATE = 2;      // 表单值不为空则验证
    
    //网站配置信息
    protected $config = NULL;
    // 当前数据库操作对象
    protected $db = NULL;
    // 主键名称
    protected $pk = 'id';
    // 主键是否自动增长
    protected $autoinc = FALSE;
    // 数据表前缀
    protected $def = NULL;
    // 模型名称
    protected $name = '';
    // 数据库编码
    protected $coding = '';
    // 数据库名称
    // 数据库名称
    protected $dbName = '';
    //数据库配置
    protected $connection = '';
    // 数据表名(不包含表前缀)
    protected $tableName = '';
    // 实际数据表名(包含表前缀)
    protected $trueTableName = '';
    // 最近错误信息
    protected $error = '';
    // 字段信息
    protected $fields = array();
    // 数据信息
    protected $data = array();
    // 查询表达式参数
    protected $options = array();
    protected $_validate = array();  // 自动验证定义
    protected $_auto = array();  // 自动完成定义
    protected $_map = array();  // 字段映射定义
    protected $_scope = array();  // 命名范围定义
    // 是否自动检测数据表字段信息
    protected $autoCheckFields = TRUE;
    // 是否批处理验证
    protected $patchValidate = FALSE;
    // 链操作方法列表
    protected $methods = array('order', 'alias', 'having', 'group', 'lock', 'distinct', 'auto', 'filter', 'validate', 'result', 'token');
    //开启分站功能的数据表
    protected $sitetable = array('ad_order', 'admin_announcement', 'zhaopinhui', 'zhaopinhui_com', 'zhaopinhui_pic', 'news_base', 'news_content', 'resume_expect', 'member', 'company_job', 'resume', 'user_entrust', 'user_entrust_record', 'down_resume', 'look_resume', 'company', 'company_cert', 'company_msg', 'company_news', 'company_order', 'company_pay', 'company_product', 'once_job', 'resume_tiny', 'userid_msg', 'userid_job', 'look_job', 'admin_link', 'px_subject', 'px_train_news', 'px_teacher', 'lt_info', 'lt_job', 'report', 'invoice_record', 'company_statis', 'px_train', 'partjob', 'hotjob', 'px_baoming', 'px_zixun', 'company_show', 'resume_show', 'banner', 'px_banner', 'px_train_show', 'rebates', 'lt_talent', 'member_log', 'login_log', 'user_change', 'company_account');
    
    //此数组针对insert_into方法。目的是添加附表数据的时候,不加入当前站的did,而是存member表中的did。
    // protected $sitetadd=array('ad','admin_announcement','zhaopinhui','news_content','member','resume','company','once_job','px_train','resume_tiny','admin_link','lt_info','partjob','hotjob');
    
    protected $admindir;
    protected $siteadmindir;
    
    protected $logininfo;
    
    public function __construct($db, $def, $logininfo = array(), $tpl = '') {
        global $coding, $config, $adminDir, $siteAdminDir;
        
        $this->db = $db;
        $this->tp = '';//未查到在哪用到
        $this->def = $def;
        $this->md = $coding;
        $this->config = $config;
        if (!empty($logininfo)) {
            $this->uid = $logininfo['uid'];
            $this->username = $logininfo['username'];
            $this->usertype = $logininfo['usertype'];
        }
        $this->admindir = $adminDir;
        $this->siteadmindir = $siteAdminDir;
        $this->tpl = $tpl;
        
        if (!($this->config['sy_wapdomain'])) {
            
            $this->config['sy_wapdomain'] = $this->config['sy_weburl'] . '/' . $this->config['sy_wapdir'];
        } else {
            
            if ($config['sy_wapssl'] == '1') {
                $protocol = 'https://';
            } else {
                $protocol = 'http://';
            }
            
            if (strpos($this->config['sy_wapdomain'], 'http://') === FALSE && strpos($this->config['sy_wapdomain'], 'https://') === FALSE) {
                $this->config['sy_wapdomain'] = $protocol . $this->config['sy_wapdomain'];
            }
        }
        if ($adminDir || !$siteAdminDir) {
            //$this->sitetadd = array();
            $this->sitetable = array();
        }
        // oss关闭时,oss地址为服务器地址
        if (!isset($this->config['sy_oss']) || (isset($this->config['sy_oss']) && $this->config['sy_oss'] == 2)) {
            
            $this->config['sy_ossurl'] = $this->config['sy_weburl'];
        }
    }
    
    /**
     * 设置数据对象的值
     * @access public
     * @param string $name 名称
     * @param mixed $value 值
     * @return void
     */
    public function __set($name, $value) {
        // 设置数据对象属性
        $this->data[$name] = $value;
    }
    
    /**
     * 获取数据对象的值
     * @access public
     * @param string $name 名称
     * @return mixed
     */
    public function __get($name) {
        return isset($this->data[$name]) ? $this->data[$name] : NULL;
    }
    
    /**
     * 检测数据对象的值
     * @access public
     * @param string $name 名称
     * @return boolean
     */
    public function __isset($name) {
        return isset($this->data[$name]);
    }
    
    /**
     * 销毁数据对象的值
     * @access public
     * @param string $name 名称
     * @return void
     */
    public function __unset($name) {
        unset($this->data[$name]);
    }
    
    // 回调方法 初始化模型
    protected function _initialize() {
    }
    
    function get_table_fields($tableName) {
        include(CONFIG_PATH . 'db.config.php');
        $mysqli = new mysqli($db_config['dbhost'], $db_config['dbuser'], $db_config['dbpass'], $db_config['dbname']);
        $query = $mysqli->query("SHOW COLUMNS FROM $tableName");
        $tableFields = array();
        while ($row = $query->fetch_assoc()) {
            $tableFields[] = $row['Field'];
        }
        return $tableFields;
    }
    
    
    function insert_into($table, $data = array()) {
        $value = array();
        $this->db->connect();
        include(PLUS_PATH . 'dbstruct.cache.php');
        $TableFullName = $this->def . $table;
        $fields = $this->get_table_fields($TableFullName);
        if (!$fields) {
            return FALSE;
        }
        if (!is_array($data)) {
            return FALSE;
        }
        foreach ($data as $key => $v) {
            if (in_array($key, $fields)) {
                $v = $this->FilterStr($v);
                $value[] = "`" . $key . "`='" . $this->db->escape_string($v) . "'";
            }
        }
        
        $value = @implode(",", $value);
        if (!$value) {
            return FALSE;
        }
        return $this->DB_insert_once($table, $value);
    }
    
    function update_once($table, $data = array(), $where = array()) {
        
        $this->db->connect();
        $value = array();
        include(PLUS_PATH . 'dbstruct.cache.php');
        $TableFullName = $this->def . $table;
        $fields = $this->get_table_fields($TableFullName);
        if (!is_array($data) || !is_array($where)) {
            return FALSE;
        }
        if (!$fields) {
            return FALSE;
        }
        
        //        var_dump($$TableFullName);exit();
//        if (is_array($where)) {
//            $fields = array_keys($where);
//        } else {
//            return FALSE;
//        }
//        var_dump($fields);exit();
        
        
        foreach ($data as $key => $v) {
            if (!in_array($key, $fields)) {
                continue;
            }
            if (is_array($v)) {
                
                if ($v[0] == '+') {
                    
                    $value[] = '`' . $key . '` = `' . $key . '` + ' . $this->db->escape_string($v[1]);
                } elseif ($v[0] == '-') {
                    
                    $value[] = '`' . $key . '` = `' . $key . '` - ' . $this->db->escape_string($v[1]);
                    
                } else if ($v[0] == '=') {
                    
                    $value[] = '`' . $key . '`  = ' . $this->db->escape_string($v[1]);
                    
                    
                } elseif ($v[0] == 'CASE') {
                    
                    
                    $casesql = '`' . $key . '` =  CASE `' . $this->db->escape_string($v[1]) . '`';
                    
                    foreach ($v[2] as $ck => $cv) {
                        
                        $casesql .= " WHEN '" . $ck . "' THEN '" . $this->db->escape_string($cv) . "' ";
                    }
                    
                    $casesql .= 'END';
                    
                    $value[] = $casesql;
                } elseif ($v[0] == 'DATE_ADD') {
                    
                    $value[] = '`' . $key . '` = DATE_ADD(`' . $key . '` , INTERVAL ' . $this->db->escape_string($v[1]) . ' DAY )';
                    
                } elseif ($v[0] == 'concat') {
                    
                    $value[] = '`' . $key . '` = concat(`' . $key . '` , ",' . $this->db->escape_string($v[1]) . ' ")';
                } else {
                    
                    $this->db->show_error();
                }
                
            } else {
                
                $v = $this->FilterStr($v);
                
                $value[] = "`" . $key . "`='" . $this->db->escape_string($v) . "'";
            }
            
        }
        
        
        $whereNew = $this->checkWhere($where);
        
        $value = @implode(',', $value);
        
        if ($value != '' && $whereNew != '') {
            
            return $this->DB_update_all($table, $value, $whereNew);
        } else {
            return FALSE;
        }
        
    }
    
    function FilterStr($str) {
        $str = stripslashes($str);
        return $str;
    }
    
    function Memcache_set($name, $value = "") {
        
        global $config;
        
        if (isset($config['ismemcache']) && $config['ismemcache'] == 2) {
            return FALSE;
        }
        if (!empty($config['memcachehost']) && !empty($config['memcacheport']) && !empty($config['memcachetime'])) {
            
            $memcachehost = $config['memcachehost'];//所在服务器
            $memcacheport = $config['memcacheport'];//所在服务器端口
            $memcachezip = 0;//是否支持解压缩
            $memcachetime = $config['memcachetime'];//缓存时间
            
            $name = md5(str_replace(array(" ", "`", "'", ".", "=", "!"), "", $name));
            
            if (!extension_loaded('memcache')) return;
            
            $memcache = new memcache();
            
            if (!@class_exists($memcache)) {
                return;
            }
            
            $memcache->connect($memcachehost, $memcacheport) or die ("Memcache连接失败或您的服务器不支持Memcache,请在后台关闭!");
            
            $val = $memcache->get($name);
            
            if (!is_array($val)) {
                $val = $value;
                $memcache->set($name, $value, $memcachezip, $memcachetime);
            }
            $memcache->close();
            return $val;
        } else {
            return FALSE;
        }
    }
    
    /**
     * 通用数量查询$tablename,$where = 1, $select="*"
     */
    function DB_select_num($tablename, $where = '', $select = "*", $tablename2 = '', $special = '') {
        if (!$this->checkTableName($tablename)) {
            
            return FALSE;
        }
        $cachename = $tablename . $where;
        if (!$return = $this->Memcache_set($cachename)) {//获取是否存在memcache
            if ($tablename2) {
                if ($this->siteadmindir && $special == '') {
                    if (in_array($tablename, $this->sitetable) && is_numeric($this->config['did'])) {
                        $Where = 'a.`did`=' . $this->config['did'] . "' and " . $Where;
                    }
                    if (in_array($tablename2, $this->sitetable) && is_numeric($this->config['did'])) {
                        $Where = 'b.`did`=' . $this->config['did'] . "' and " . $Where;
                    }
                }
                
                $SQL = "SELECT count($select) as num FROM " . $this->def . $tablename . " as a," . $this->def . $tablename2 . " as b  WHERE $where";
            } else {
                
                
                if ($this->siteadmindir && $special == '') {
                    
                    $where = $this->site_fetchsql($where, $tablename);
                }
                $SQL = "SELECT count($select) as num FROM " . $this->def . $tablename;
                
                if ($where) {
                    $SQL .= " WHERE " . $where;
                }
            }
            $query = $this->db->query($SQL);
            while ($row = $this->db->fetch_array($query)) {
                $return = $row['num'];
            }
            $this->Memcache_set($cachename, $return);//设置memcache
        }
        if ($return < 1) {
            $return = '0';
        }
        return $return;
    }
    
    function select_num($tablename, $where = array(), $select = "*") {
        if (!$this->checkTableName($tablename)) {
            
            return FALSE;
        }
        if ($this->siteadmindir) {
            if (in_array($tablename, $this->sitetable)) {
                if (is_numeric($this->config['did'])) {
                    $where['did'] = $this->config['did'];
                }
            }
        }
        $whereNew = $this->checkWhere($where);
        $cachename = $tablename . $whereNew;
        
        if (!$return = $this->Memcache_set($cachename)) {//获取是否存在memcache
            
            $SQL = "SELECT count($select) as num FROM " . $this->def . $tablename . $whereNew;
            
            $query = $this->db->query($SQL);
            while ($row = $this->db->fetch_array($query)) {
                $return = $row['num'];
            }
            $this->Memcache_set($cachename, $return);//设置memcache
        }
        if ($return < 1) {
            $return = '0';
        }
        return $return;
    }
    
    /**
     * 通用query查询 $tablename,$where = 1, $select="*"
     *$special:标记某些特殊查询,不使用did参数。
     *2016-1-14        LGL
     */
    function DB_select_query($tablename, $where = 1, $select = "*", $special = '') {
        if (!$this->checkTableName($tablename)) {
            
            return FALSE;
        }
        if ($this->siteadmindir) {
            
            $where = $this->site_fetchsql($where, $tablename);
        }
        $SQL = "SELECT $select FROM " . $this->def . $tablename . " WHERE $where";
        $query = $this->db->query($SQL);
        return $query;
    }
    
    /**
     * 通用all查询 $tablename,$where = 1, $select="*"
     *$special:标记某些特殊查询,不使用did参数。
     */
    function DB_select_all($tablename, $where = 1, $select = "*", $special = '') {
        if (!$this->checkTableName($tablename)) {
            
            return FALSE;
        }
        
        $cachename = $tablename . $where;
        if (!$row_return = $this->Memcache_set($cachename)) {//获取是否存在memcache
            $row_return = array();
            if ($this->siteadmindir && $special == '') {
                
                $where = $this->site_fetchsql($where, $tablename);
            }
            $SQL = "SELECT $select FROM `" . $this->def . $tablename . "`";
            
            if ($where) {
                $SQL .= " WHERE " . $where;
            }
            
            $query = $this->db->query($SQL);
            while ($row = $this->db->fetch_array($query)) {
                $row_return[] = $row;
            }
            $this->Memcache_set($cachename, $row_return);//设置memcache
        }
        return $row_return;
    }
    
    //新多条查询
    function select_all($tablename, $where = array(), $select = "*", $special = '') {
        if (!$this->checkTableName($tablename)) {
            
            return FALSE;
        }
        
        if ($this->siteadmindir && $special == '') {
            
            if (in_array($tablename, $this->sitetable)) {
                if (is_numeric($this->config['did'])) {
                    $where['did'] = $this->config['did'];
                }
            }
        }
        $whereNew = $this->checkWhere($where);
        
        $cachename = $tablename . $whereNew;
        
        if (!$row_return = $this->Memcache_set($cachename)) {//获取是否存在memcache
            
            $row_return = array();
            
            /*if($this->siteadmindir&&$special==''){
 
                    $whereNew = $this->site_fetchsql($whereNew,$tablename);
            }  */
            
            $SQL = "SELECT $select FROM `" . $this->def . $tablename . "`" . $whereNew;
            $query = $this->db->query($SQL);
            
            while ($row = $this->db->fetch_array($query)) {
                
                $row_return[] = $row;
            }
            $this->Memcache_set($cachename, $row_return);//设置memcache
        }
        return $row_return;
    }
    
    /**
     * 通用all查询双表 $tablename1,$tablename2, $where = 1, $select = "*"
     */
    function DB_select_alls($tablename1, $tablename2, $where = 1, $select = "*") {
        if (!$this->checkTableName($tablename1)) {
            
            return FALSE;
        }
        if (!$this->checkTableName($tablename2)) {
            
            return FALSE;
        }
        $cachename = $tablename1 . $tablename2 . $where;
        if (!$row_return = $this->Memcache_set($cachename)) {//获取是否存在memcache
            
            
            if ($this->siteadmindir) {
                
                if (in_array($tablename1, $this->sitetable) && is_numeric($this->config['did'])) {
                    $where = 'a.`did`=' . $this->config['did'] . " and " . $where;
                }
                if (in_array($tablename2, $this->sitetable) && is_numeric($this->config['did'])) {
                    
                    
                    $where = 'b.`did`=' . $this->config['did'] . " and " . $where;
                }
            }
            $SQL = "SELECT $select FROM " . $this->def . $tablename1 . " as a," . $this->def . $tablename2 . " as b WHERE $where";
            
            $query = $this->db->query($SQL);
            while ($row = $this->db->fetch_array($query)) {
                $row_return[] = $row;
            }
            $this->Memcache_set($cachename, $row_return);//设置memcache
        }
        
        return $row_return;
    }
    
    /**
     * 单表单条插入 $tablename, $value
     */
    function DB_insert_once($tablename, $value) {
        if (!$this->checkTableName($tablename)) {
            
            return FALSE;
        }
        if (in_array($tablename, $this->sitetable) && strpos($value, '`did`') === FALSE) {
            $value .= ",`did`='" . $this->config['did'] . "'";
        }
        $SQL = "INSERT INTO `" . $this->def . $tablename . "` SET " . $value;
        
        $this->db->query("set sql_mode=''");
        $this->db->query($SQL);
        $nid = $this->db->insert_id();
        return $nid;
    }
    
    //一次插入多条数据,方便本地测试数据库构造数据进行测试
    function DB_insert_multi($tablename, $valueArr) {
        // INSERT INTO `roles` (`uid`,`rid`) VALUES
        //    (534,14),(535,14),(536,14),(537,14),(539,14)
        if (!$this->checkTableName($tablename)) {
            return FALSE;
        }
        include(PLUS_PATH . 'dbstruct.cache.php');
        $TableFullName = $this->def . $tablename;
        /////获取表的字段
        
        if (!isset($$TableFullName)) {
            $this->error = '表结构缓存文件不存在';
            return FALSE;
        }
        
        if (is_array($$TableFullName)) {
            $fieldsArr = array_keys($$TableFullName);
        }
        if ($fieldsArr) {
            $fields = array();
            foreach ($valueArr[0] as $f => $v) {
                if (in_array($f, $fieldsArr)) {
                    $fields [] = "`$f`";
                }
            }
            $fields = implode(',', $fields);
            
            $values = array();
            foreach ($valueArr as $r) {
                $arr = array();
                foreach ($r as $k => $v) {
                    if (in_array($k, $fieldsArr)) {
                        $arr [] = "'" . $this->db->escape_string($v) . "'";
                    }
                }
                $values [] = '(' . implode(',', $arr) . ')';
            }
            $values = implode(',', $values);
            $SQL = "INSERT INTO `{$this->def}{$tablename}` ($fields) VALUES $values";
            $this->db->query("set sql_mode=''");
            $return = $this->db->query($SQL);
            return $return;
        }
    }
    
    /**
     * 更新 $tablename, $value, $where = 1
     */
    function DB_update_all($tablename, $value, $where, $pecial = '') {
        if (!$this->checkTableName($tablename)) {
            
            return FALSE;
        }
        
        if (empty($where) || empty($value)) {
            return FALSE;
        }
        
        $SQL = "UPDATE `" . $this->def . $tablename . "` SET $value  " . $where;
        
        
        $this->db->query("set sql_mode=''");
        $return = $this->db->query($SQL);
        return $return;
    }
    
    /**
     * 删除 $tablename, $value, $where = 1
     */
    function DB_delete_all($tablename, $where, $limit = 'limit 1', $pecial = '', $norecycle = '') {
        if (!$this->checkTableName($tablename)) {
            
            return FALSE;
        }
        if (empty($where)) {
            return FALSE;
        }
        if ($pecial != $tablename) {
            //快速创建简历保存数据不进入回收站
            if (!in_array($tablename, array('temporary_resume')) && $norecycle != '1') {
                $this->insert_recycle($tablename, $this->site_fetchsql($where, $tablename));//先执行回收站
            }
            $SQL = "DELETE FROM `" . $this->def . $tablename . "` WHERE " . $this->site_fetchsql($where, $tablename) . " $limit";
        } else {
            //快速创建简历保存数据不进入回收站
            if (!in_array($tablename, array('temporary_resume')) && $norecycle != '1') {
                $this->insert_recycle($tablename, $where);//先执行回收站
            }
            $SQL = "DELETE FROM `" . $this->def . $tablename . "` WHERE " . $where . " $limit";
        }
        
        $this->db->query("set `sql_mode`=''");
        return $this->db->query($SQL);
    }
    
    /**
     * @desc 删除数据库
     * @param    $tablename    数据表名;
     * $where        删除数据表数据查询条件;
     * $limit        删除记录数
     * $pecial        暂未发现使用
     * $norecycle    1:不做回收站插入操作
     */
    function delete_all($tablename, $where = array(), $limit = 'limit 1', $special = '', $norecycle = '') {
        
        if (!$this->checkTableName($tablename)) {
            
            return FALSE;
        }
        include(PLUS_PATH . 'dbstruct.cache.php');
        
        if ($this->siteadmindir && $special == '') {
            
            if (in_array($tablename, $this->sitetable)) {
                if (is_numeric($this->config['did'])) {
                    $where['did'] = $this->config['did'];
                }
            }
        }
        
        $whereNew = $this->checkWhere($where);
        
        
        if (!empty($whereNew)) {
            
            //快速创建简历保存数据不进入回收站
            if (!in_array($tablename, array('temporary_resume')) && $norecycle != '1') {
                
                $this->insert_recycle($tablename, $whereNew);//先执行回收站
            }
            
            $SQL = "DELETE FROM `" . $this->def . $tablename . "` " . $whereNew . " " . $limit;
            
        } else {
            
            return FALSE;
        }
        
        $this->db->query("set `sql_mode`=''");
        return $this->db->query($SQL);
    }
    
    /**
     * 删除进入回收站
     *
     * @param $tablename
     * @param $where
     * @return bool
     */
    function insert_recycle($tablename, $where) {
        
        if (!$this->checkTableName($tablename)) {
            
            return FALSE;
        }
        //回收站同一次操作生成数据MD5用作识别同一次操作的标识符
        if (!$this->__isset('recyclemd5')) {
            
            $recyclemd5 = md5($tablename . $where);
            
            $this->__set('recyclemd5', $recyclemd5);
            
        } else {
            //获取当前操作模块的统一标识符
            $recyclemd5 = $this->__get('recyclemd5');
        }
        
        if (!isset($_GET['isdel']) || $_GET['isdel'] != "all") {
            
            $value = "tablename = '" . $tablename . "', ";
            $value .= "ctime = '" . time() . "', ";
            
            if (isset($_SESSION['auid']) && isset($_SESSION['ausername']) && $_SESSION['auid'] && $_SESSION['ausername']) {
                
                $username = $_SESSION['ausername'];
                $uid = $_SESSION['auid'];
            } else {
                
                $username = isset($this->username) ? $this->username : '';
                $uid = isset($this->uid) ? $this->uid : '';
            }
            
            $value .= "uid = '" . $uid . "', ";
            $value .= "username = '" . $username . "', ";
            $value .= "uri = '" . $_SERVER['REQUEST_URI'] . "', ";
            
            $query = $this->db->query("SELECT * FROM " . $this->def . $tablename . "  $where");
            $row_del = array();
            while ($row = $this->db->fetch_assoc($query)) {
                $row_del[] = $row;
            }
            
            if (!empty($row_del)) {
                
                foreach ($row_del as $delvalue) {
                    
                    $this->DB_insert_once('recycle', $value . "`body`='" . serialize($delvalue) . "',`ident`='" . $recyclemd5 . "'");
                }
            }
        }
    }
    
    /**
     * 自定义SQL执行 便于多表联合、left join等组合查询语句
     */
    function DB_query_all($sql, $type = 'one') {
        
        $this->db->query("set sql_mode=''");
        
        $query = $this->db->query($sql);
        
        if ($type == 'all') {
            
            while ($row = $this->db->fetch_array($query)) {
                $return[] = $row;
            }
        } else {
            
            $return = $this->db->fetch_array($query);
        }
        return $return;
    }
    
    /**
     * 通用单条查询$tablename,$where = 1, $select="*"
     */
    function DB_select_once($tablename, $where = 1, $select = "*", $special = '') {
        
        if (!$this->checkTableName($tablename)) {
            
            return FALSE;
        }
        
        $cachename = $tablename . $where;
        
        if (!$return = $this->Memcache_set($cachename)) {//获取是否存在memcache
            if ($this->siteadmindir && $special == '') {
                $where = $this->site_fetchsql($where, $tablename);
            }
            $SQL = 'SELECT ' . $select . ' FROM ' . $this->def . $tablename;
            if ($where) {
                $SQL .= ' WHERE ' . $where;
            }
            $SQL .= ' LIMIT 1';
            $query = $this->db->query($SQL);
            $return = $this->db->fetch_array($query);
            $this->Memcache_set($cachename, $return);//设置memcache
        }
        return $return;
    }
    
    //新单条查询
    function select_once($tablename, $where = array(), $select = "*", $special = '') {
        
        if (!$this->checkTableName($tablename)) {
            
            return FALSE;
        }
        
        if ($this->siteadmindir && $special == '') {
            
            if (in_array($tablename, $this->sitetable)) {
                if (is_numeric($this->config['did'])) {
                    $where['did'] = $this->config['did'];
                }
            }
        }
        $whereNew = $this->checkWhere($where);
        
        $cachename = $tablename . $whereNew;
        
        if (!$return = $this->Memcache_set($cachename)) {//获取是否存在memcache
            /*if($this->siteadmindir    &&    $special==''){
                $whereNew = $this->site_fetchsql($whereNew,$tablename);
            }*/
            $SQL = 'SELECT ' . $select . ' FROM ' . $this->def . $tablename . $whereNew;
            
            $SQL .= ' LIMIT 1';
            
            $query = $this->db->query($SQL);
            $return = $this->db->fetch_array($query);
            $this->Memcache_set($cachename, $return);//设置memcache
        }
        return $return;
    }
    
    function member_log($content, $opera = '', $type = '', $uid = NULL, $usertype = NULL) {//会员日志
        if (!$uid && !$usertype) {
            $uid = intval($_COOKIE['uid']);
            $usertype = intval($_COOKIE['usertype']);
        }
        if ($uid && $usertype) {
            $value = "`uid`='" . $uid . "',";
            $value .= "`usertype`='" . $usertype . "',";
            $value .= "`content`='" . $content . "',";
            $value .= "`opera`='" . $opera . "',";
            $value .= "`type`='" . $type . "',";
            $value .= "`ip`='" . fun_ip_get() . "',";
            $value .= "`ctime`='" . time() . "'";
            $this->DB_insert_once("member_log", $value);
        }
    }
    
    function FormatOptions($Options) {
        if (!is_array($Options)) {
            return array('field' => '*', 'where' => '');
        }
        $WhereStr = '';
        if ($Options['field']) {
            $Field = $Options['field'];
            unset($Options['field']);
        } else {
            $Field = '*';
        }
        if ($Options['special']) {
            $special = $Options['special'];
            unset($Options['special']);
        }
        if ($Options['groupby']) {
            $WhereStr .= ' group by ' . $Options['groupby'];
        }
        if ($Options['orderby']) {
            $WhereStr .= ' order by ' . $Options['orderby'];
        }
        
        if ($Options['desc']) {
            $WhereStr .= " " . $Options['desc'];
        }
        if ($Options['limit']) {
            $WhereStr .= ' limit ' . $Options['limit'];
        }
        return array('field' => $Field, 'order' => $WhereStr, "special" => $special);
    }
    
    function FormatWhere($Where) {
        $WhereStr = '1';
        foreach ($Where as $k => $v) {
            //两种方式:1,'uid'=>1 ; 2,'`uid` in (1,2,3)'
            //TODO:检查字段是否存在
            if (is_numeric($k)) {
                if ((substr(trim($v), 0, 3) == 'and') || (substr(trim($v), 0, 2) == 'or')) {
                    $WhereStr .= ' ' . $v;
                } elseif ($v) {
                    $WhereStr .= ' and ' . $v;
                }
            } else {
                /* where允许的格式:
                    $where = array('uid' => $this->uid,
                        'name <> ' => '',
                        'age > '   => '18',
                        'height <' => '65'
                    );
                */
                if (strpos($k, '<>') > 0) {
                    $position = strpos($k, '<>');
                    $fieldName = trim(substr($k, 0, $position));
                    $WhereStr .= ' and `' . $fieldName . '` <> \'' . $v . '\'';
                } elseif (strpos($k, '<') > 0) {
                    $position = strpos($k, '<');
                    $fieldName = trim(substr($k, 0, $position));
                    $WhereStr .= ' and `' . $fieldName . '` < \'' . $v . '\'';
                } elseif (strpos($k, '>') > 0) {
                    $position = strpos($k, '>');
                    $fieldName = trim(substr($k, 0, $position));
                    $WhereStr .= ' and `' . $fieldName . '` > \'' . $v . '\'';
                } else {
                    $WhereStr .= ' and `' . $k . '`=\'' . $v . '\'';
                }
            }
        }
        return $WhereStr;
    }
    
    function FormatValues($Values) {
        $ValuesStr = '';
        foreach ($Values as $k => $v) {
            //两种方式:1,'uid'=>1 ; 2,'`uid` in (1,2,3)'
            //TODO:检查字段是否存在
            if (preg_match("/^[a-zA-Z0-9_]+$/", $k)) {
                if (preg_match('/^[0-9]+$/', $k)) {
                    $FiledList = @explode(',', $v);
                    if (is_array($FiledList)) {
                        foreach ($FiledList as $Fv) {
                            $FvList = @explode('=', $Fv);
                            if ($FvList[1]) {
                                if (strpos($FvList[1], '+') > 0) {
                                    $FiledV = @explode('+', $FvList[1]);
                                    $ValuesStr .= ',`' . str_replace("`", '', $FvList[0]) . '`=`' . str_replace("`", '', $FiledV[0]) . '`+\'' . intval(str_replace("'", '', $FiledV[1])) . '\'';
                                }
                                if (strpos($FvList[1], '-') > 0) {
                                    $FiledV = @explode('-', $FvList[1]);
                                    $ValuesStr .= ',`' . str_replace("`", '', $FvList[0]) . '`=`' . str_replace("`", '', $FiledV[0]) . '`-\'' . intval(str_replace("'", '', $FiledV[1])) . '\'';
                                }
                                
                            }
                        }
                    }
                } else {
                    $ValuesStr .= ',`' . $k . '`=\'' . $v . '\'';
                }
            }
            
        }
        return substr($ValuesStr, 1);
    }
    
    //提醒处理
    function RemindDeal($TableName, $Values = array(), $Where = array()) {
        if (!$this->checkTableName($TableName)) {
            
            return FALSE;
        }
        $ValuesStr = $this->FormatValues($Values);
        $WhereStr = $this->FormatWhere($Where);
        $this->DB_update_all($TableName, $ValuesStr, $WhereStr);
    }
    
    function site_fetchsql($Where, $TableName, $SplitChar = ' and ') {
        if (!$this->checkTableName($TableName)) {
            
            return FALSE;
        }
        if (in_array($TableName, $this->sitetable)) {
            if (is_array($Where) && is_numeric($this->config['did'])) {
                $Where['did'] = $this->config['did'];
            } else if (is_numeric($this->config['did'])) {
                $Where = '`did`=' . $this->config['did'] . $SplitChar . $Where;
            }
        }
        return $Where;
    }
    
    //调用分页,$table表名,$where条件,$pageurl分页链接,$limit条数,$rowsname模板接收变量,$pagenavname分页模板接收变量
    function get_page($table, $where = '', $pageurl = '', $limit = 20, $field = '*', $rowsname = 'rows') {
        if (!$this->checkTableName($table)) {
            
            return FALSE;
        }
        $rows = array();
        $page = $_GET['page'] < 1 ? 1 : $_GET['page'];
        $ststrsql = ($page - 1) * $limit;
        $num = $this->DB_select_num($table, $where);
        if ($num > $limit) {
            $pages = ceil($num / $limit);
            $pagenav = Page($page, $num, $limit, $pageurl, $notpl = FALSE, NULL);
        }
        $rows = $this->DB_select_all($table, $where . ' limit ' . $ststrsql . ',' . $limit, $field);
        return array('total' => $num, 'pagenav' => $pagenav, $rowsname => $rows);
    }
    
    function fetch_assoc() {
        return $this->db->fetch_assoc();
    }
    
    function checkTableName($table) {
        
        if (preg_match('/^[_a-z]{2,30}$/i', $table)) {
            return TRUE;
        } else {
            return FALSE;
        }
        
    }
    
    
    /*
    *    $data        :    where条件, 字符串value 默认==:$where[id] = '1';
    *                                数组  value:$where['id'] = array('>','1','or/and');根据传入的or and 异或查询 默认AND
    *    $key        :    PHPYUNBTW PHPYUNBTWEND 使用()组合优先级组合条件 如 (id>0 AND id<1)
    *    $whereNew    :    拼接后的SQL条件,默认以AND 连接
     */
    function checkWhere($where) {
        
        
        $whereNew = '';
        
        if (!empty($where) && is_array($where)) {
            
            $limit = '';
            
            if (!empty($where['limit'])) {
                
                if (is_array($where['limit'])) {
                    
                    $limit = ' LIMIT ' . (int)$where['limit'][0] . ',' . (int)$where['limit'][1];
                    
                } else {
                    
                    
                    $limit = ' LIMIT ' . (int)$where['limit'];
                }
                
                unset($where['limit']);
                
            }
            
            $orderby = '';
            
            if (!empty($where['orderby'])) {
                
                if (is_array($where['orderby'])) {
                    
                    $orderby = ' ORDER BY ';
                    
                    foreach ($where['orderby'] as $key => $value) {
                        
                        if ($key > 0) {
                            $orderby .= ',';
                        }
                        
                        $orders = @explode(',', $value);
                        
                        $orderby .= $orders[0] . ' ';
                        $orderby .= strtoupper(trim($orders[1])) == 'ASC' ? 'ASC' : 'DESC';
                        
                        $whereFiled[] = $orders[0];
                        
                        
                    }
                    
                    
                } elseif (stripos($where['orderby'], 'CASE WHEN') !== FALSE) {
                    //CASE THEN END 条件排序
                    
                    $orderby = ' ORDER BY ' . $where['orderby'];
                    $whereFiled[] = 'CASE';
                    
                } else {
                    
                    $orders = @explode(',', $where['orderby']);
                    
                    $orderby = ' ORDER BY ' . $orders[0] . ' ';
                    $orderby .= strtoupper(trim($orders[1])) == 'ASC' ? 'ASC' : 'DESC';
                    
                    $whereFiled[] = $orders[0];
                }
                unset($where['orderby']);
                
            }
            
            if (!empty($where['orderbyfield'])) {
                
                if (is_array($where['orderbyfield']) && count($where['orderbyfield']) == 2) {
                    
                    $orderby = ' ORDER BY field(' . $where['orderbyfield'][0] . ',' . $where['orderbyfield'][1] . ')';
                    
                    $whereFiled[] = $where['orderbyfield'][0];
                    
                }
                
                unset($where['orderbyfield']);
            }
            
            $groupby = $having = '';
            
            if (!empty($where['groupby'])) {
                
                //   GROUP BY    和   HAVING 联合查询
                //   $key    :   having ;    $value  :   array();
                //   例如            :     array('having' => array('distance' => array('<', 20, ''), 'x' => array('<>', 0, 'AND')))
                if (!empty($where['having'])) {
                    
                    $groupby = ' GROUP  BY ' . $where['groupby'];
                    
                    $whereFiled[] = $where['groupby'];
                    
                    foreach ($where['having'] as $key => $value) {
                        
                        if (is_array($value)) {
                            
                            //   HAVING 多条件查询; $value[2] : 异或查询
                            if ($value[2] == 'OR' || $value[2] == 'or') {
                                
                                $btnAndOR = ' OR ';
                            } else if ($value[2] == 'AND' || $value[2] == 'and') {
                                
                                $btnAndOR = ' AND ';
                            } else {
                                
                                $btnAndOR = '';
                            }
                            
                            $having = $btnAndOR;
                            $having .= $this->spilceWhere($key, $value);
                            
                            $whereFiled[] = $key;
                        }
                        
                    }
                    
                    $groupby .= ' HAVING ' . $having;
                    
                    unset($where['having']);
                    
                } else {
                    
                    $groupby = ' GROUP  BY ' . $where['groupby'];
                    
                    $whereFiled[] = $where['groupby'];
                }
                
                unset($where['groupby']);
                
            }
            
            foreach ($where as $key => $value) {
                
                //PHPYUNBTWSTART_A  PHPYUNBTWEND_A  PHPYUNBTWSTART_B  PHPYUNBTWEND_B 这种可以组成多个()
                // PHPYUNBTWSTART_A_DOUBLE、PHPYUNBTWEND_B_DOUBLE 考虑有需要多重括号的方式,增加此种写法
                //考虑到部分需要使用()执行优先级条件查询判断的情况
                if (strpos($key, 'PHPYUNBTWSTART') !== FALSE) {
                    
                    if ($whereNew != '') {
                        $btwAndOr = ($value == 'OR' || $value == 'or') ? ' OR ' : ' AND ';
                    } else {
                        $btwAndOr = '';
                    }
                    
                    $whereNew .= $btwAndOr . '(';
                    // 带_DOUBLE为需要一个多的开始括号情况
                    if (strpos($key, '_DOUBLE') !== FALSE) {
                        $whereNew .= '(';
                    }
                    //标识符 用于判断是否是()内首项条件 非首项条件 必须使用 AND/OR 连接
                    $btwStr = 1;
                    
                } elseif (strpos($key, 'PHPYUNBTWEND') !== FALSE) {
                    
                    $whereNew .= ')';
                    // 带_DOUBLE为需要一个多的结束括号情况
                    if (strpos($key, '_DOUBLE') !== FALSE) {
                        $whereNew .= ')';
                    }
                    //取消标识符
                    $btwStr = 0;
                    
                } else {
                    
                    //where格式不为纯字符串,则按照操作符函数进行处理
                    if (!empty($value) && is_array($value)) {
                        
                        //同一个字段 多项条件组合
                        if (is_array($value[0])) {
                            
                            foreach ($value as $sonv) {
                                
                                if ($whereNew != '' && $btwStr != 1) {
                                    
                                    $whereNew .= ($sonv[2] == 'OR' || $sonv[2] == 'or') ? ' OR ' : ' AND ';
                                }
                                //根据value[0] 判断SQL操作符 并进行组合SQL语句
                                
                                $whereNew .= $this->spilceWhere($key, $sonv);
                                
                                $whereFiled[] = $key;
                                
                                $btwStr = 0;
                                
                            }
                            
                        } else {
                            if ($whereNew != '' && $btwStr != 1) {
                                $whereNew .= (isset($value[2]) && ($value[2] == 'OR' || $value[2] == 'or')) ? ' OR ' : ' AND ';
                            }
                            //根据value[0] 判断SQL操作符 并进行组合SQL语句
                            
                            $whereNew .= $this->spilceWhere($key, $value);
                            
                            $whereFiled[] = $key;
                        }
                        
                    } else {
                        
                        //首项条件 排除AND连接符
                        
                        if ($whereNew != '' && $btwStr != 1) {
                            $whereNew .= ' AND ';
                        }
                        //纯字符串格式默认为 = 操作符
                        $whereNew .= "`" . $key . "`='" . $this->db->escape_string($value) . "'";
                        
                        $whereFiled[] = $key;
                    }
                    $btwStr = 0;
                }
            }
        }
        // 验证字段
        
        if (!empty($whereFiled)) {
            foreach ($whereFiled as $value) {
                
                if (!preg_match("/^[a-zA-Z0-9_`()]{1,30}$/", $value)) {
                    
                    $noFields = 1;
                    break;
                }
            }
        }
        
        if (!isset($noFields)) {
            
            
            if ($whereNew) {
                $whereNew = ' WHERE ' . $whereNew;
                
            }
            $whereNew .= $groupby . $orderby . $limit;
            return $whereNew;
        } else {
            
            $this->db->show_error();
        }
        
        
    }
    
    function spilceWhere($daraKey, $dataV) {
        
        $Operator = array('=', '>', '>=', '<', '<=', '<>', 'in', 'notin', 'isnull', 'notnull', 'like', 'findin', 'between', 'unixtime', 'like%', 'dateformat', 'in_s', 'regexp');
        
        if (in_array($dataV[0], $Operator)) {
            
            switch ($dataV[0]) {
                
                case    'notin'        :
                    $sqlString = "`$daraKey` not in (" . $this->db->escape_string($dataV[1]) . ")";
                    break;
                
                case    'in'        :
                    $sqlString = "`$daraKey`  in (" . $dataV[1] . ")";
                    break;
                
                case    'isnull'    :
                    $sqlString = "`$daraKey` is null";
                    break;
                
                case    'notnull'    :
                    $sqlString = "`$daraKey` is not null";
                    break;
                
                case    'like'        :
                    $sqlString = "`$daraKey` LIKE ('%" . $this->db->escape_string($dataV[1]) . "%')";
                    break;
                
                case    'findin'    :
                    $sqlString = "FIND_IN_SET('" . $this->db->escape_string($dataV[1]) . "',`$daraKey`)";
                    break;
                
                case    'between'    :
                    $betweens = explode(',', $dataV[1]);
                    $sqlString = "$daraKey between $betweens[0] AND $betweens[1]";
                    break;
                
                case    'unixtime'  :
                    $sqlString = "UNIX_TIMESTAMP(`$daraKey`) " . $this->db->escape_string($dataV[1]) . " '$dataV[2]'";
                    break;
                
                case    'like%'        :
                    $sqlString = "`$daraKey` LIKE ('" . $this->db->escape_string($dataV[1]) . "%')";
                    break;
                
                case    'dateformat':
                    $sqlString = "date_format(`$daraKey`,'" . $dataV[1] . "')=date_format(now(),'" . $this->db->escape_string($dataV[1]) . "')";
                    break;
                // 字符串型的in
                case    'in_s'        :
                    $sqlString = "`$daraKey`  in ('" . $dataV[1] . "')";
                    break;
                // 处理值匹配
                case    'regexp'    :
                    $sqlString = "(`$daraKey` REGEXP '" . $dataV[1] . "')=0";
                    break;
                default                :
                    // 传入字段中包含sql函数的,两边不需要加`
                    $keystr = !preg_match("/[)]/", $daraKey) ? "`$daraKey` " : "$daraKey ";
                    $sqlString = $keystr . $this->db->escape_string($dataV[0]) . " '$dataV[1]'";
            }
            
        } else {
            
            $this->db->show_error();
        }
        
        return $sqlString;
        
    }
    
    function uc_open() {
        include APP_PATH . 'data/api/uc/config.inc.php';
        include APP_PATH . '/api/uc/include/db_mysql.class.php';
        include APP_PATH . '/api/uc/uc_client/client.php';
        
        return $ucinfo;
    }
}
 
?>