X-Git-Url: http://git.dj3c1t.com/?a=blobdiff_plain;f=web%2Fapp%2Fdata%2Fmodules%2Fsql%2Fmw_data_config.php;fp=web%2Fapp%2Fdata%2Fmodules%2Fsql%2Fmw_data_config.php;h=ca45faac16b88f212dadba44c261e92a1bab7ebd;hb=7cf7609a7e236347374c1b21777a9698bcd1726c;hp=0d6f4d2274998bd614733e91e8b6864ec0557766;hpb=29b6377f43bf4477e04b57069cf779ac1b913bdb;p=mtweb diff --git a/web/app/data/modules/sql/mw_data_config.php b/web/app/data/modules/sql/mw_data_config.php index 0d6f4d2..ca45faa 100644 --- a/web/app/data/modules/sql/mw_data_config.php +++ b/web/app/data/modules/sql/mw_data_config.php @@ -5,57 +5,64 @@ function config($key = null){ $sgbd = $this->sgbd(); $value = false; - if(isset($key)){ - $sql = - "SELECT `value` FROM #--config" - ." WHERE `key`=".$this->eq($key); - $rst = $sgbd->query($sql); - if(!isset($rst)) return false; - if($v_rst = $sgbd->fetch_assoc($rst)) $value = $v_rst["value"]; - else $value = ""; - $sgbd->free_result($rst); - } - else{ - $value = array(); - $sql = - "SELECT * FROM #--config"; - $rst = $sgbd->query($sql); - if(!isset($rst)) return false; - while($v_rst = $sgbd->fetch_assoc($rst)) $value[$v_rst["key"]] = $v_rst["value"]; - $sgbd->free_result($rst); + 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; - $sql = "SELECT count(*) as n FROM #--config" - ." WHERE `key`=".$this->eq($key); - $rst = $sgbd->query($sql); - if(!isset($rst)) return false; - if($v_rst = $sgbd->fetch_assoc($rst)) $exists = $v_rst["n"]; - $sgbd->free_result($rst); + 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($this->config_exists($key)) $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).")"; - $rst = $sgbd->query($sql); - if(!isset($rst)) return false; + 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(); - return $sgbd->query("DELETE FROM #--config WHERE `key`=".$this->eq($key)) ? true : false; + try{ + $sql = "DELETE FROM #--config WHERE `key`=".$this->eq($key); + $sgbd->query($sql); + } + catch(Exception $e) { return false; } + return true; } }