+++ /dev/null
-<?php
-
- class mw_data_config extends mw_data{
-
- function config($key = null){
- $sgbd = $this->sgbd();
- $value = false;
- try{
- if(isset($key)){
- $value = "";
- $sql = "SELECT `value` FROM #--config WHERE `key`=".$this->eq($key);
- $rst = $sgbd->query($sql);
- if($v_rst = $sgbd->fetch_assoc($rst)) $value = $v_rst["value"];
- $sgbd->free_result($rst);
- }
- else{
- $value = array();
- $sql = "SELECT * FROM #--config";
- $rst = $sgbd->query($sql);
- while($v_rst = $sgbd->fetch_assoc($rst)) $value[$v_rst["key"]] = $v_rst["value"];
- $sgbd->free_result($rst);
- }
- }
- catch(Exception $e) { $value = false; }
- return $value;
- }
-
- function config_exists($key){
- $sgbd = $this->sgbd();
- $exists = false;
- try{
- $sql = "SELECT count(*) as n FROM #--config WHERE `key`=".$this->eq($key);
- $rst = $sgbd->query($sql);
- if($v_rst = $sgbd->fetch_assoc($rst)) $exists = $v_rst["n"];
- $sgbd->free_result($rst);
- }
- catch(Exception $e) { $exists = false; }
- return $exists;
- }
-
- function set_config($key, $value){
- $sgbd = $this->sgbd();
- if(($exists = $this->config_exists($key)) === false) return false;
- try{
- if($exists) $sql =
- "UPDATE #--config"
- ." SET `value`=".$this->eq($value)
- ." WHERE `key`=".$this->eq($key);
- else $sql =
- "INSERT INTO #--config"
- ." VALUES(NULL, ".$this->eq($key).", ".$this->eq($value).")";
- $sgbd->query($sql);
- }
- catch(Exception $e) { return false; }
- return true;
- }
-
- function del_config($key){
- $sgbd = $this->sgbd();
- try{
- $sql = "DELETE FROM #--config WHERE `key`=".$this->eq($key);
- $sgbd->query($sql);
- }
- catch(Exception $e) { return false; }
- return true;
- }
-
- }
-
-?>
\ No newline at end of file