You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.4 KiB

<?php
namespace Gateway;
use Config\ConnectClass;
use Config\Connection;
use PDO;
use PDOException;
class GatewayUser
{
/**
* @var Connection
*/
private Connection $connection;
public function __construct()
{
try{
$this->connection = (new ConnectClass)->connect();
}catch(PDOException $e){
throw new PDOException($e->getMessage(), $e->getCode(), $e);
}
}
public function getUserPassword(string $login): array
{
$query = "SELECT id,password FROM `user` WHERE login = :login";
$this->connection->executeQuery($query, array(
':login' => array($login, PDO::PARAM_STR)
));
$result = $this->connection->getResults();
if(empty($result))
return array("-1","");
return $result[0];
}
public function addUser(String $login, String $password): void
{
$query = "INSERT INTO `user`(login,password) VALUES(:login, :password)";
$this->connection->executeQuery($query, array(
':login' => array($login, PDO::PARAM_STR),
':password' => array($password, PDO::PARAM_STR)
));
}
public function getAllUsers(): ?array
{
$query = "SELECT login FROM `user`";
$this->connection->executeQuery($query);
$result = $this->connection->getResults();
if(empty($result))
return null;
return $result;
}
}