first commit
This commit is contained in:
31
app/Model/userModel.php
Normal file
31
app/Model/userModel.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
namespace Blog\Model;
|
||||
|
||||
use Blog\Entity\user;
|
||||
use Blog\Database\database;
|
||||
use PDO;
|
||||
|
||||
class UserModel {
|
||||
private $db;
|
||||
|
||||
public function __construct() {
|
||||
$this->db = Database::getConnection();
|
||||
}
|
||||
|
||||
public function getUserByUsername(string $username):?User {
|
||||
$query = $this->db->prepare(<<<SQL
|
||||
SELECT id, username, password
|
||||
FROM users
|
||||
WHERE username = :username
|
||||
LIMIT 1
|
||||
SQL);
|
||||
$query->bindParam(':username', $username);
|
||||
$query->execute();
|
||||
|
||||
$row = $query->fetchObject();
|
||||
if(!$row)
|
||||
return null;
|
||||
|
||||
return new User($row->id, $row->username, $row->password);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user