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.
SAE_2A_FA-Reseau_ALICA/dal/gateway/CompteGateway.php

82 lines
2.6 KiB

<?php
class CompteGateway
{
private Connection $con;
/**
* @param $con
*/
public function __construct(Connection $con){
$this->con = $con;
}
public function insert(string $email, string $pseudo, string $motDePasse){
$query='INSERT INTO Compte VALUES (:e, :p, :m)';
$this->con->executeQuery($query, array(
':e' => array($email, PDO::PARAM_STR),
':p' => array($pseudo, PDO::PARAM_STR),
':m' => array($motDePasse, PDO::PARAM_STR)
));
}
public function updateEmail(string $email, string $newEmail){
$query='UPDATE Compte SET email=:new WHERE email=:e';
$this->con->executeQuery($query, array(
':e' => array($email, PDO::PARAM_STR),
':new' => array($newEmail, PDO::PARAM_STR)
));
}
public function updatePseudo(string $email, string $pseudo){
$query='UPDATE Compte SET pseudo=:new WHERE email=:e';
$this->con->executeQuery($query, array(
':e' => array($email, PDO::PARAM_STR),
':new' => array($pseudo, PDO::PARAM_STR)
));
}
public function updateMotDePasse(string $email, string $password){
$query='UPDATE Compte SET motDePasse=:new WHERE email=:e';
$this->con->executeQuery($query, array(
':e' => array($email, PDO::PARAM_STR),
':new' => array($password, PDO::PARAM_STR)
));
}
public function delete(string $email){
$query='DELETE FROM Compte WHERE email=:e';
$this->con->executeQuery($query, array(
':e' => array($email, PDO::PARAM_STR)
));
}
public function findByPseudo(string $pseudo){
$query = 'SELECT * FROM Compte WHERE pseudo=:p';
$this->con->executeQuery($query, array(
':p' => array($pseudo, PDO::PARAM_STR)
));
$res=$this->con->getResults();
return new Compte($res[0]['email'],$res[0]['pseudo'],$res[0]['motDePasse']);
}
public function findByEmail(string $email){
$query='SELECT * FROM Compte WHERE email=:e';
$this->con->executeQuery($query, array(
':e' => array($email, PDO::PARAM_STR),
));
$res=$this->con->getResults();
return new Compte($res[0]['email'],$res[0]['pseudo'],$res[0]['motDePasse']);
}
public function getAll(){
$query='SELECT * FROM Compte';
$this->con->executeQuery($query);
$res=$this->con->getResults();
$array=[];
foreach($res as $r){
$array[]=new Compte($r['email'],$r['pseudo'],$r['motDePasse']);
}
return $array;
}
}