c0d71b322d25d96ffd425f30120f12c4371406b0
bernd Ein paar neue Klassen

bernd authored 16 years ago

1) <?php
2) 
3) require_once('inc/db_connect.php');
4) require_once('inc/base.php');
5) require_once('inc/debug.php');
6) 
7) 
8) abstract class KeksData
9) {
10)   protected $default_table;
11)   
12)   protected $data = array();
13) 
14)   function __get($key)
15)   {
16)     if (array_key_exists($key, $this->data))
17)       return $this->data[$key];
18)     elseif (isset($this->$key))
19)       return $this->$key;
20)     // else werfe fehler
21)   }
22) 
23)   function __set($key, $value)
24)   {
25)     if (array_key_exists($key, $this->data))
26)       $this->data[$key] = $value;
27)     elseif (isset($this->$key))
28)       $this->$key = $value;
29)     else
30)       $this->data[$key] = $value;
31)   }
32) 
33)   protected function setup()
34)   {
35)     $fields = array();
36)     $res = db_query("DESCRIBE {$this->default_table}");
37)     while ($f = mysql_fetch_object($res))
38)     {
39)       $fields[$f->Field] = $f->Default;
40)     }
41)     $this->data = $fields;
bernd Domain-Klasse benutzen

bernd authored 16 years ago

42)     $this->data['id'] = NULL;
bernd Ein paar neue Klassen

bernd authored 16 years ago

43)   }
44) 
45) 
46)   function getData($fields, $restriction = NULL, $table = NULL)
47)   {
48)     $where = '';
49)     if ($restriction)
50)       $where = 'WHERE '.$restriction;
51)     if (! $table)
52)       $table = $this->default_table;
53)     if (is_array($fields))
54)       $fields = implode(',', $fields);
55)     
56)     $res = db_query("SELECT {$fields} FROM {$table} {$where}");
57)     $return = array();
58)     while ($arr = mysql_fetch_assoc($res))
59)       array_push($return, $arr);
60)     return $return;
61)   }
62) 
63) 
64)   function loadByID($id)
65)   {
66)     $id = (int) $id;
67)     $res = $this->getData('*', "id={$id} LIMIT 1");
bernd Domain-Klasse benutzen

bernd authored 16 years ago

68)     if (count($res) < 1)
69)       return false;