26 lines
769 B
PHP
26 lines
769 B
PHP
<?php
|
|
|
|
class User
|
|
{
|
|
public static function create(string $name, string $email, string $password): bool
|
|
{
|
|
$sql = 'INSERT INTO users (name, email, password_hash) VALUES (:name, :email, :password_hash)';
|
|
$statement = Database::connection()->prepare($sql);
|
|
|
|
return $statement->execute([
|
|
'name' => $name,
|
|
'email' => $email,
|
|
'password_hash' => password_hash($password, PASSWORD_DEFAULT),
|
|
]);
|
|
}
|
|
|
|
public static function findByEmail(string $email): ?array
|
|
{
|
|
$statement = Database::connection()->prepare('SELECT * FROM users WHERE email = :email LIMIT 1');
|
|
$statement->execute(['email' => $email]);
|
|
|
|
$user = $statement->fetch();
|
|
return $user ?: null;
|
|
}
|
|
}
|