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.
45 lines
1.6 KiB
45 lines
1.6 KiB
<?php
|
|
include('Connection.php');
|
|
|
|
Class UserGateway{
|
|
private Connection $con;
|
|
|
|
public function __construct(Connection $con){
|
|
$this->con=$con;
|
|
}
|
|
|
|
public function insert(string $username,string $email,string $passwd):int{
|
|
|
|
// récupération id
|
|
$query='SELECT id_user FROM Users WHERE id_user >= ALL (SELECT id_user FROM Users);';
|
|
$this->con->executeQuery($query);
|
|
$result=$this->con->getResults();
|
|
foreach($result as $row){
|
|
$id=$row['id_user'] + 1;
|
|
}
|
|
// insertion user
|
|
$query='INSERT INTO Users VALUES (:id,:username,:email,:passwd,CURRENT_DATE,false);';
|
|
$this->con->executeQuery($query,array(':id' => array($id,PDO::PARAM_INT),':username' => array($u->username,PDO::PARAM_STR),':email' => array($u->email,PDO::PARAM_STR),':passwd' => array($u->passwd,PDO::PARAM_STR)));
|
|
return $id;
|
|
}
|
|
|
|
public function delete(int $id){
|
|
|
|
// supretion user
|
|
$query='DELETE FROM Users WHERE id_user = :id;';
|
|
$this->con->executeQuery($query,array(':id' => array($id,PDO::PARAM_INT)));
|
|
}
|
|
|
|
public function getFavorite(int $id):array{
|
|
|
|
//obtention favoris d'un user
|
|
$query='SELECT * FROM Quote WHERE id_quote IN (SELECT id_quote IN Favorite f JOIN User u ON u.id_user = f.user WHERE id_user = :id);';
|
|
$this->con->executeQuery($query,array(':id' => array($id,PDO::PARAM_INT)));
|
|
$result=$this->con->getResults();
|
|
return $result;
|
|
}
|
|
|
|
}
|
|
$uG = new UserGateway(new Connection("pgsql:host=londres;dbname=dbkekentin","kekentin",""));
|
|
$uG->delete(2);
|
|
?>
|