4 * Baseclass for Models in this imaginary ORM
7 public $id, $attributes;
8 static function create($params) {
9 $obj = new self($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);
31 foreach ($rs as $idx => $row) {
32 if ($row['id'] == $id) {
33 $rec->attributes = array_merge($rec->attributes, $params);
34 $dbh->update($idx, $rec->attributes);
40 static function destroy($id) {
44 foreach ($rs as $idx => $row) {
45 if ($row['id'] == $id) {
46 $rec = new self($dbh->destroy($idx));
52 static function all() {
57 public function __construct($params) {
58 $this->id = $params["id"] || null;
59 $this->attributes = $params;
61 public function save() {
63 $this->attributes['id'] = $dbh->pk();
64 $dbh->insert($this->attributes);
66 public function to_hash() {
67 return $this->attributes;