|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <?php
-
- class
- User
- {
- var $id;
- var $name;
- var $pass;
- var $inheritance_code;
-
- public static function
- find (
- int $id):
- Self
- {
- $sql = "
- SELECT
- *
- FROM
- user
- WHERE
- id = $id";
- $result = $GLOBALS['__db_connection'] -> query ($sql)
- or die ("db_select error $sql");
-
- $row = $this -> db -> fetch_array ($result);
-
- $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)
- VALUES
- ('{$this -> name}',
- '{$this -> pass}',
- '{$this -> inheritance_code}',
- NOW())";
- $GLOBALS['__db_connection'] -> query ($sql)
- or die ("db_insert error $sql");
-
- $this -> id = $GLOBALS['__db_connection'] -> insert_id;
-
- return $this;
- }
- }
-
|