4 * Baseclass for Models in this imaginary ORM
7 public $id, $attributes;
8 static function create($params) {
9 $obj = new self(get_object_vars($params));
13 static function find($id) {
16 foreach ($dbh->rs() as $rec) {
17 if ($rec['id'] == $id) {
18 $found = new self($rec);
24 static function update($id, $params) {
26 $rec = self::find($id);
33 foreach ($rs as $idx => $row) {
34 if ($row['id'] == $id) {
35 $rec->attributes = array_merge($rec->attributes, get_object_vars($params));
36 $dbh->update($idx, $rec->attributes);
42 static function destroy($id) {
46 foreach ($rs as $idx => $row) {
47 if ($row['id'] == $id) {
48 $rec = new self($dbh->destroy($idx));
54 static function all() {
59 public function __construct($params) {
60 $this->id = isset($params['id']) ? $params['id'] : null;
61 $this->attributes = $params;
63 public function save() {
65 $this->attributes['id'] = $dbh->pk();
66 $dbh->insert($this->attributes);
68 public function to_hash() {
69 return $this->attributes;