<?php
// required headers
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
  
// include database and object files
include_once '../config/database.php';
include_once '../objects/identite.php';
  
// instantiate database and identite object
$database = new Database();
$db = $database->getConnection();
  
// initialize object
$identite = new Identite($db);
  
// read products will be here
// query products
$stmt = $identite->read();
$num = $stmt->rowCount();
  
// check if more than 0 record found
if($num>0){
  
    // products array
    $identites_arr=array();
    $identites_arr["records"]=array();
  
    // retrieve our table contents
    // fetch() is faster than fetchAll()
    // http://stackoverflow.com/questions/2770630/pdofetchall-vs-pdofetch-in-a-loop
    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
        // extract row
        // this will make $row['name'] to
        // just $name only
        extract($row);
  
        $identite_item=array(
            "id" => $id,
            "login" => $login,
            "password" => $password,
            "pseudo" => $pseudo,
            "âge" => $âge,
            "poids" => $poids,
            "taille" => $taille,
            "sexe" => $sexe,
            "niveau_du_sport" =>$niveau_du_sport
        );
  
        array_push($identites_arr["records"], $identite_item);
    }
  
    // set response code - 200 OK
    http_response_code(200);
  
    // show products data in json format
    echo json_encode($identites_arr);
}
  
// no products found will be here
else{
  
    // set response code - 404 Not found
    http_response_code(404);
  
    // tell the user no products found
    echo json_encode(
        array("message" => "No products found.")
    );
}
