Rev | Line | |
---|
[1] | 1 | <?php |
---|
| 2 | |
---|
| 3 | class data_config extends data |
---|
| 4 | { |
---|
| 5 | |
---|
| 6 | function config($key = null) |
---|
| 7 | { $value = false; |
---|
| 8 | try |
---|
| 9 | { |
---|
| 10 | if(isset($key)) |
---|
| 11 | { $sql = "SELECT `value` FROM #--configuration WHERE `key`=".$this->eq($key); |
---|
| 12 | $rst = $this->sql->query($sql); |
---|
| 13 | if($v_rst = $this->sql->fetch_assoc($rst)) $value = $v_rst["value"]; |
---|
| 14 | else $value = ""; |
---|
| 15 | $this->sql->free_result($rst); |
---|
| 16 | } |
---|
| 17 | else |
---|
| 18 | { $value = array(); |
---|
| 19 | $sql = "SELECT * FROM #--configuration"; |
---|
| 20 | $rst = $this->sql->query($sql); |
---|
| 21 | while($v_rst = $this->sql->fetch_assoc($rst)) $value[$v_rst["key"]] = $v_rst["value"]; |
---|
| 22 | $this->sql->free_result($rst); |
---|
| 23 | } |
---|
| 24 | } |
---|
| 25 | catch(Exception $_e) { $value = false; } |
---|
| 26 | return $value; |
---|
| 27 | } |
---|
| 28 | |
---|
| 29 | function config_exists($key) |
---|
| 30 | { $exists = false; |
---|
| 31 | try |
---|
| 32 | { $sql = "SELECT count(*) as n FROM #--configuration WHERE `key`=".$this->eq($key); |
---|
| 33 | $rst = $this->sql->query($sql); |
---|
| 34 | if($v_rst = $this->sql->fetch_assoc($rst)) $exists = $v_rst["n"]; |
---|
| 35 | $this->sql->free_result($rst); |
---|
| 36 | } |
---|
| 37 | catch(Exception $_e) {} |
---|
| 38 | return $exists; |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | function set_config($key, $value) |
---|
| 42 | { try |
---|
| 43 | { if($this->config_exists($key)) $sql = |
---|
| 44 | "UPDATE #--configuration" |
---|
| 45 | ." SET `value`=".$this->eq($value) |
---|
| 46 | ." WHERE `key`=".$this->eq($key); |
---|
| 47 | else $sql = |
---|
| 48 | "INSERT INTO #--configuration" |
---|
| 49 | ." VALUES(".$this->eq($key).", ".$this->eq($value).")"; |
---|
| 50 | $this->sql->query($sql); |
---|
| 51 | return true; |
---|
| 52 | } |
---|
| 53 | catch(Exception $_e) {} |
---|
| 54 | return false; |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | ?> |
---|
Note: See
TracBrowser
for help on using the repository browser.