|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- <?php
-
- class
- User
- {
- public int $id;
- public string $name;
- public string $pass;
- public string $inheritance_code;
-
- public static function
- find (
- int $id):
- Self
- {
- $sql = "
- SELECT
- *
- FROM
- users
- WHERE
- id = $id";
- $result = $GLOBALS['__db_connection'] -> query ($sql)
- or die ("db_select error $sql");
- $row = $result -> fetch_array ();
-
- $self = new Self;
- $self -> id = $id;
- $self -> name = $row['name'];
- $self -> pass = $row['pass'];
- $self -> inheritance_code = $row['inheritance_code'];
-
- return $self;
- }
-
- public function
- insert ():
- Self
- {
- $sql = "
- INSERT INTO
- users (
- name,
- pass,
- inheritance_code,
- created_at,
- modified_at)
- VALUES
- ('{$this -> name}',
- '{$this -> pass}',
- '{$this -> inheritance_code}',
- NOW(),
- NOW())";
- $GLOBALS['__db_connection'] -> query ($sql)
- or die ("db_insert error $sql");
-
- $this -> id = $GLOBALS['__db_connection'] -> insert_id;
-
- return $this;
- }
- }
-
|