table_common_setting.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: table_common_setting.php 30476 2012-05-30 07:05:06Z zhangguosheng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class table_common_setting extends discuz_table
  12. {
  13. public function __construct() {
  14. $this->_table = 'common_setting';
  15. $this->_pk = 'skey';
  16. parent::__construct();
  17. }
  18. public function fetch($skey, $auto_unserialize = false) {
  19. $data = DB::result_first('SELECT svalue FROM '.DB::table($this->_table).' WHERE '.DB::field($this->_pk, $skey));
  20. return $auto_unserialize ? (array)unserialize($data) : $data;
  21. }
  22. public function fetch_all($skeys = array(), $auto_unserialize = false){
  23. $data = array();
  24. $where = !empty($skeys) ? ' WHERE '.DB::field($this->_pk, $skeys) : '';
  25. $query = DB::query('SELECT * FROM '.DB::table($this->_table).$where);
  26. while($value = DB::fetch($query)) {
  27. $data[$value['skey']] = $auto_unserialize ? (array)unserialize($value['svalue']) : $value['svalue'];
  28. }
  29. return $data;
  30. }
  31. public function update($skey, $svalue){
  32. return DB::insert($this->_table, array($this->_pk => $skey, 'svalue' => is_array($svalue) ? serialize($svalue) : $svalue), false, true);
  33. }
  34. public function update_batch($array) {
  35. $settings = array();
  36. foreach($array as $key => $value) {
  37. $key = addslashes($key);
  38. $value = addslashes(is_array($value) ? serialize($value) : $value);
  39. $settings[] = "('$key', '$value')";
  40. }
  41. if($settings) {
  42. return DB::query("REPLACE INTO ".DB::table('common_setting')." (`skey`, `svalue`) VALUES ".implode(',', $settings));
  43. }
  44. return false;
  45. }
  46. public function skey_exists($skey) {
  47. return DB::result_first('SELECT skey FROM %t WHERE skey=%s LIMIT 1', array($this->_table, $skey)) ? true : false;
  48. }
  49. public function fetch_all_not_key($skey) {
  50. return DB::fetch_all('SELECT * FROM '.DB::table($this->_table).' WHERE skey NOT IN('.dimplode($skey).')');
  51. }
  52. public function fetch_all_table_status() {
  53. return DB::fetch_all('SHOW TABLE STATUS');
  54. }
  55. public function get_tablepre() {
  56. return DB::object()->tablepre;
  57. }
  58. public function update_count($skey, $num) {
  59. return DB::query("UPDATE %t SET svalue = svalue + %d WHERE skey = %s", array($this->_table, $num, $skey), false, true);
  60. }
  61. }
  62. ?>