Skip to content

Instantly share code, notes, and snippets.

@fesor
Last active March 12, 2024 00:02
Show Gist options
  • Select an option

  • Save fesor/d84451fc6cf00ea62ca5 to your computer and use it in GitHub Desktop.

Select an option

Save fesor/d84451fc6cf00ea62ca5 to your computer and use it in GitHub Desktop.
Доступ к данным или как мы учились не замечать базу данных
class User extends ActiveRecord {
public $id;
public $email;
public $password;
public $firstName;
public $lastName;
}
/* maps all this on table:
Table users
------------------------
| id | int |
| email | string |
| password | string |
| first_name | string |
| last_name | string |
------------------------ */
abstract class ActiveRecord {
public function save() {
if ($this->isNewRecord()) {
$this->insert();
} else {
$this->update();
}
}
public function update() {
$this->db->update($this->tableName, $this->attrs, ['id' => $this->id]);
}
public function insert() {
$this->db->insert($this->tableName, $this->attrs);
}
public function delete() {
$this->db->insert($this->tableName, $this->attrs);
}
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment