forked from arunoda-susiripala/Code51
-
Notifications
You must be signed in to change notification settings - Fork 2
/
metadata_helper.php
40 lines (33 loc) · 916 Bytes
/
metadata_helper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
class Metadata{
public static function set($key,$value,$namespace='global'){
$CI= get_instance();
$db=$CI->db;
$sql="insert into metadata values('"
.$key."','"
.$value."','"
.$namespace."') "
." ON DUPLICATE KEY UPDATE `value`='$value'";
return $db->query($sql);
}
public static function get($key,$namespace='global'){
$CI= get_instance();
$db=$CI->db;
$sql="SELECT * FROM metadata WHERE `key` LIKE '$key' AND `namespace` ".
"LIKE '$namespace'";
$query= $db->query($sql);
if($query->result()==null) return null;
$rtn=array();
foreach($query->result() as $val){
$rtn[$val->namespace][$val->key]=$val->value;
}
return $rtn;
}
public static function delete($key,$namespace='global'){
$CI= get_instance();
$db=$CI->db;
$sql="DELETE FROM metadata WHERE `key` LIKE '$key' AND `namespace` ".
"LIKE '$namespace'";
return $db->query($sql);
}
}