diff --git a/public/index.php b/public/index.php index b3e6bb8..14b0756 100644 --- a/public/index.php +++ b/public/index.php @@ -24,13 +24,13 @@ function get_base_path() { } $basePath = get_base_path(); -$pdo = new Connexion(get_database()); +$con = new Connexion(get_database()); // routes initialization $router = new AltoRouter(); $router->setBasePath($basePath); -$sampleFormController = new SampleFormController(new FormResultGateway($pdo)); +$sampleFormController = new SampleFormController(new FormResultGateway($con)); $router->map("GET", "/", fn() => $sampleFormController->displayForm()); $router->map("POST", "/submit", fn() => $sampleFormController->submitForm($_POST)); diff --git a/sql/database.php b/sql/database.php index 8f445bc..0830ed8 100644 --- a/sql/database.php +++ b/sql/database.php @@ -1,7 +1,10 @@ pdo = $pdo; } + /** + * execute a request + * @param string $query + * @param array $args + * @return void + */ public function exec(string $query, array $args) { $stmnt = $this->pdo->prepare($query); foreach ($args as $name => $value) { @@ -23,6 +29,12 @@ class Connexion { $stmnt->execute(); } + /** + * Execute a request, and return the returned rows + * @param string $query the SQL request + * @param array $args an array containing the arguments label, value and type: ex: `[":label" => [$value, PDO::PARAM_TYPE]` + * @return array the returned rows of the request + */ public function fetch(string $query, array $args): array { $stmnt = $this->pdo->prepare($query); foreach ($args as $name => $value) {