X-Git-Url: http://git.dj3c1t.com/?a=blobdiff_plain;f=mw%2Fapp%2Fdata%2Fmodules%2Fsql%2Fmw_data_config.php;fp=mw%2Fapp%2Fdata%2Fmodules%2Fsql%2Fmw_data_config.php;h=ca45faac16b88f212dadba44c261e92a1bab7ebd;hb=36ed114046cbe3d72a3589230e9f306a54fcc79d;hp=0000000000000000000000000000000000000000;hpb=281c96e95451269f2614684b8de5be25862c8374;p=mtweb diff --git a/mw/app/data/modules/sql/mw_data_config.php b/mw/app/data/modules/sql/mw_data_config.php new file mode 100644 index 0000000..ca45faa --- /dev/null +++ b/mw/app/data/modules/sql/mw_data_config.php @@ -0,0 +1,70 @@ +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