diff --git a/WEB/Config/Config.php b/WEB/Config/Config.php index 1846fe2d..f3d0caa3 100644 --- a/WEB/Config/Config.php +++ b/WEB/Config/Config.php @@ -14,7 +14,7 @@ $rep = __DIR__ . '/../'; // $password = 'p'; // SQULITE3 -// $dsn = 'sqlite:./Model/scripted.db'; +$dsn = 'sqlite:./Model/scripted.db'; // $user = null; // $password = null; diff --git a/WEB/Config/Connection.php b/WEB/Config/Connection.php index 644ed7a7..0ecf2b5e 100644 --- a/WEB/Config/Connection.php +++ b/WEB/Config/Connection.php @@ -19,8 +19,23 @@ class Connection extends SQLite3 { - function __construct() + private $stmt; + private $result; + function __construct($dsn) { - $this->open('./Model/scripted.db'); + $this->open($dsn); + } + + public function executeQuery(string $query, array $parameters = []) :bool { + $this->stmt = $this->prepare($query); + foreach ($parameters as $name => $value) { + $this->stmt->bindValue($name, $value[0], $value[1]); + } + $this->result=$this->stmt->execute(); + return $this->result; + } + + public function getResults(): array { + return $this->result->fetchArray(); } } \ No newline at end of file diff --git a/WEB/Controller/FrontController.php b/WEB/Controller/FrontController.php index e7f34540..75da9c81 100644 --- a/WEB/Controller/FrontController.php +++ b/WEB/Controller/FrontController.php @@ -6,7 +6,6 @@ class FrontController session_start(); // $role=$_SESSION['role']; // $action=$_REQUEST['action']; - echo "front"; new UserController(); } } \ No newline at end of file diff --git a/WEB/Controller/UserController.php b/WEB/Controller/UserController.php index 8f80c0b1..1f5da15f 100644 --- a/WEB/Controller/UserController.php +++ b/WEB/Controller/UserController.php @@ -2,26 +2,17 @@ class UserController { - // function __construct(){ - // $ - // } private Connection $con; function __construct() { - global $dsn, $user, $password; - // $this->con=new Connection($dsn); - $this->con=new Connection (); + global $dsn; + $this->con=new Connection ($dsn); try{ global $rep, $vues, $error; $action=$_REQUEST['action']; - echo "userController"; switch($action) { case NULL: - $db= new Connection(); - $db->exec('INSERT INTO Utilisateur VALUES ("e","e","e", false)' ); - $res=$db->exec('SELECT * FROM Utilisateur' ); - echo $res; - // require ($rep.$vues['main']); + $this->goToHome(); break; case "signUp": $this->signUp(); diff --git a/WEB/index.php b/WEB/index.php index 2c6dfbdd..0d87319e 100644 --- a/WEB/index.php +++ b/WEB/index.php @@ -3,23 +3,21 @@ require_once('./Config/Config.php'); require_once('./Config/Autoload.php'); Autoload::charger(); -$db = new Connection(); -//Insert a new user in the database -// $db->exec('INSERT INTO Utilisateur VALUES ("e","e","e", false)'); -$stm=$db->prepare("INSERT INTO Utilisateur VALUES (:email, :password, :pseudo, :admin)"); -$stm->bindValue(':email', "e",SQLITE3_TEXT); -$stm->bindValue(':password', "e" ,SQLITE3_TEXT); -$stm->bindValue(':pseudo', "e", SQLITE3_TEXT); -$stm->bindValue(':admin', 0, SQLITE3_INTEGER); -$stm->execute(); +// $db = new Connection(); +// $stm=$db->prepare("INSERT INTO Utilisateur VALUES (:email, :password, :pseudo, :admin)"); +// $stm->bindValue(':email', "e",SQLITE3_TEXT); +// $stm->bindValue(':password', "e" ,SQLITE3_TEXT); +// $stm->bindValue(':pseudo', "e", SQLITE3_TEXT); +// $stm->bindValue(':admin', 0, SQLITE3_INTEGER); +// $stm->execute(); -$res = $db->query('SELECT * FROM Utilisateur'); -// Select all the users in the database -while ($row = $res->fetchArray()) { - echo $row['email'] . " " . $row['password'] . " " . $row['pseudo'] . " " . $row['admin'] . " "; -} +// $res = $db->query('SELECT * FROM Utilisateur'); +// // Select all the users in the database +// while ($row = $res->fetchArray()) { +// echo $row['email'] . " " . $row['password'] . " " . $row['pseudo'] . " " . $row['admin'] . " "; +// } -// $control = new FrontController(); +$control = new FrontController(); //session_regenerate_id(true);