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.
30 lines
1.0 KiB
30 lines
1.0 KiB
<?php
|
|
include('Connection.php');
|
|
include('user.php');
|
|
|
|
Class UserGateway{
|
|
private Connection $con;
|
|
|
|
public function __construct(Connection $con){
|
|
$this->con=$con;
|
|
}
|
|
|
|
public function insert(USer $u):int{
|
|
|
|
// récupération id
|
|
$query='SELECT id_user FROM Users WHERE id_user >= ALL (SELECT id_user FROM User);';
|
|
$this->con->executeQuery($query);
|
|
$result=$this->con->getResults();
|
|
$id=$result['id_user'] + 1;
|
|
|
|
// insertion user
|
|
$query='INSERT INTO Users VALUES (id=:id,username=:username,email=:email,passwd=:passwd,CURRENT_DATE);';
|
|
$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 $this->con->lastInsertId();
|
|
}
|
|
}
|
|
|
|
$u = new User("Test","1234","none","test@gmail.com");
|
|
$uG = new UserGateway(new Connection("mysql:host=localhost;dbname=dbkemondejar","",""));
|
|
$uG->insert($u);
|
|
?>
|