Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- abstract class Model
- {
- private $_data = [];
- public function __construct($data)
- {
- $this->_data = $data;
- }
- public function __get($var) { return $this->_data[$var]; }
- protected static $pk = 'id';
- protected static $table = null;
- protected static $connection; // PDO Connection
- public function find($pk)
- {
- $q = self::$connection->prepare('SELECT * FROM :table WHERE :column = :value');
- $res = $q->execute([':table' => static::$table, ':column' => static::$pk, ':value' => $pk]);
- $objects = []
- foreach ($res as $ob) {
- $objects[] = new self($ob);
- }
- return $objects;
- }
- }
- class User extends Model
- {
- protected static $table = 'users';
- }
- $users = User::find(1);
- echo $users[0]->login // возвращает поле логин
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement