Last active
March 12, 2024 00:02
-
-
Save fesor/d84451fc6cf00ea62ca5 to your computer and use it in GitHub Desktop.
Доступ к данным или как мы учились не замечать базу данных
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| 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