nouveau SQL import / maj donnees XML
[mtweb] / mw / app / data / modules / sql / mw_data_config.php
1 <?php
2
3   class mw_data_config extends mw_data{
4
5     function config($key = null){
6       $sgbd = $this->sgbd();
7       $value = false;
8       try{
9         if(isset($key)){
10           $value = "";
11           $sql = "SELECT `value` FROM #--config WHERE `key`=".$this->eq($key);
12           $rst = $sgbd->query($sql);
13           if($v_rst = $sgbd->fetch_assoc($rst)) $value = $v_rst["value"];
14           $sgbd->free_result($rst);
15         }
16         else{
17           $value = array();
18           $sql = "SELECT * FROM #--config";
19           $rst = $sgbd->query($sql);
20           while($v_rst = $sgbd->fetch_assoc($rst)) $value[$v_rst["key"]] = $v_rst["value"];
21           $sgbd->free_result($rst);
22         }
23       }
24       catch(Exception $e) { $value = false; }
25       return $value;
26     }
27
28     function config_exists($key){
29       $sgbd = $this->sgbd();
30       $exists = false;
31       try{
32         $sql = "SELECT count(*) as n FROM #--config WHERE `key`=".$this->eq($key);
33         $rst = $sgbd->query($sql);
34         if($v_rst = $sgbd->fetch_assoc($rst)) $exists = $v_rst["n"];
35         $sgbd->free_result($rst);
36       }
37       catch(Exception $e) { $exists = false; }
38       return $exists;
39     }
40
41     function set_config($key, $value){
42       $sgbd = $this->sgbd();
43       if(($exists = $this->config_exists($key)) === false) return false;
44       try{
45         if($exists) $sql =
46          "UPDATE #--config"
47         ." SET `value`=".$this->eq($value)
48         ." WHERE `key`=".$this->eq($key);
49         else $sql =
50          "INSERT INTO #--config"
51         ." VALUES(NULL, ".$this->eq($key).", ".$this->eq($value).")";
52         $sgbd->query($sql);
53       }
54       catch(Exception $e) { return false; }
55       return true;
56     }
57
58     function del_config($key){
59       $sgbd = $this->sgbd();
60       try{
61         $sql = "DELETE FROM #--config WHERE `key`=".$this->eq($key);
62         $sgbd->query($sql);
63       }
64       catch(Exception $e) { return false; }
65       return true;
66     }
67
68   }
69
70 ?>