table_common_setting.php
2.35 KB
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
<?php
/**
* [Discuz!] (C)2001-2099 Comsenz Inc.
* This is NOT a freeware, use is subject to license terms
*
* $Id: table_common_setting.php 30476 2012-05-30 07:05:06Z zhangguosheng $
*/
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
class table_common_setting extends discuz_table
{
public function __construct() {
$this->_table = 'common_setting';
$this->_pk = 'skey';
parent::__construct();
}
public function fetch($skey, $auto_unserialize = false) {
$data = DB::result_first('SELECT svalue FROM '.DB::table($this->_table).' WHERE '.DB::field($this->_pk, $skey));
return $auto_unserialize ? (array)unserialize($data) : $data;
}
public function fetch_all($skeys = array(), $auto_unserialize = false){
$data = array();
$where = !empty($skeys) ? ' WHERE '.DB::field($this->_pk, $skeys) : '';
$query = DB::query('SELECT * FROM '.DB::table($this->_table).$where);
while($value = DB::fetch($query)) {
$data[$value['skey']] = $auto_unserialize ? (array)unserialize($value['svalue']) : $value['svalue'];
}
return $data;
}
public function update($skey, $svalue){
return DB::insert($this->_table, array($this->_pk => $skey, 'svalue' => is_array($svalue) ? serialize($svalue) : $svalue), false, true);
}
public function update_batch($array) {
$settings = array();
foreach($array as $key => $value) {
$key = addslashes($key);
$value = addslashes(is_array($value) ? serialize($value) : $value);
$settings[] = "('$key', '$value')";
}
if($settings) {
return DB::query("REPLACE INTO ".DB::table('common_setting')." (`skey`, `svalue`) VALUES ".implode(',', $settings));
}
return false;
}
public function skey_exists($skey) {
return DB::result_first('SELECT skey FROM %t WHERE skey=%s LIMIT 1', array($this->_table, $skey)) ? true : false;
}
public function fetch_all_not_key($skey) {
return DB::fetch_all('SELECT * FROM '.DB::table($this->_table).' WHERE skey NOT IN('.dimplode($skey).')');
}
public function fetch_all_table_status() {
return DB::fetch_all('SHOW TABLE STATUS');
}
public function get_tablepre() {
return DB::object()->tablepre;
}
public function update_count($skey, $num) {
return DB::query("UPDATE %t SET svalue = svalue + %d WHERE skey = %s", array($this->_table, $num, $skey), false, true);
}
}
?>