gpens/sallesQuery.php

56 lines
1.4 KiB
PHP

<?php
// Connection à la BDD:
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
include 'bddpass.php';
try {
$conn = new PDO("mysql:host=localhost;dbname=savrillo", "savrillo", $bddpass, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
if($_GET["salle"] != NULL) {
$idSalle = $_GET["salle"];
$aliaz = array();
$stmt = $conn->prepare("SELECT nom FROM salleAlias WHERE salleID=?");
$stmt->execute([$idSalle]);
$resA = $stmt->fetchAll();
for($i=0;$i<count($resA);$i++)
$aliaz[$i] = $resA[$i]['nom'];
$locataires = array();
$stmt = $conn->prepare("SELECT personne FROM locataire WHERE salle=?");
$stmt->execute([$idSalle]);
$resP = $stmt->fetchAll();
for($i=0;$i<count($resP);$i++)
$locataires[$i] = $resP[$i]['personne'];
$stmt = $conn->prepare("SELECT id, nom, description FROM salles WHERE id=?");
$stmt->execute([$idSalle]);
$resS = $stmt->fetchAll();
if(count($resS)==0){
echo "404";
}else {
$out = array("id" => $resS[0]["id"], "nom" => $resS[0]["nom"], "description" => $resS[0]["description"], "aliaz" => $aliaz, "locataires" => $locataires);
echo (json_encode($out));
}
}else {
echo "Je ne connais pas cette commande ...";
}