summaryrefslogtreecommitdiff
blob: 8ad8456b009210e5241cef9a0479eb89751b5e9b (plain)
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
41
42
43
44
45
46
47
48
49
50
51
<?

	class DBCategory {
	
		private $id;
		private $name;
		private $arr_keys;
		private $table;
		private $arr_db;
		private $description;
	
		function __construct($id) {
		
			if(!is_numeric($id))
				$id = 0;
			$this->id = $id;
			
			$db =& MDB2::singleton();
			$this->table = 'category';
			
			// Go ahead and query as much as we can
			$sql = "SELECT * FROM ".$this->table." WHERE id = ".$db->quote($this->id).";";
			$this->arr_db = $db->getRow($sql);
			
			$this->arr_keys = array_keys($this->arr_db);
			unset($this->arr_keys['id']);
			
		}
		
		public function __get($var) {
			if(in_array($var, $this->arr_keys)) {
				return $this->arr_db[$var];
			} else {
				return $this->$var;
			}
		}
		
		public function __set($var, $value) {
		
			$db =& MDB2::singleton();
		
			if(in_array($var, $this->arr_keys)) {
				$arr_update = array($var => $value);
				$db->autoExecute($this->table, $arr_update, MDB2_AUTOQUERY_UPDATE, "id = ".$db->quote($this->id));
				$this->$var = $value;
			}
		}
		
	}

?>