|
- <?php
-
- class
- User
- {
- private $db;
-
- private $id;
- var $name;
- var $pass;
-
- function
- __construct ()
- {
- $config = include ('./config.php');
-
- $db_host = $config['host'];
- $db_port = $config['port'];
- $db_user = $config['user'];
- $db_pass = $config['pass'];
-
- $this -> db = new mysqli ($db_host, $db_user, $db_pass, 'goatoh_training',
- $db_port);
- }
-
- public static function
- find (
- int $id):
- Self
- {
- $sql = "
- SELECT
- *
- FROM
- user
- WHERE
- id = $id";
- $result = $this -> db -> 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'];
-
- return $self;
- }
- }
|