parent
bcc98fcbfb
commit
a32bec9a7e
@ -0,0 +1,77 @@
|
||||
-- phpMyAdmin SQL Dump
|
||||
-- version 5.1.1
|
||||
-- https://www.phpmyadmin.net/
|
||||
--
|
||||
-- Host: 127.0.0.1
|
||||
-- Generation Time: Mar 15, 2022 at 11:33 PM
|
||||
-- Server version: 10.4.22-MariaDB
|
||||
-- PHP Version: 7.4.27
|
||||
|
||||
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
|
||||
START TRANSACTION;
|
||||
SET time_zone = "+00:00";
|
||||
|
||||
|
||||
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
|
||||
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
|
||||
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
|
||||
/*!40101 SET NAMES utf8mb4 */;
|
||||
|
||||
--
|
||||
-- Database: `b1evaluation`
|
||||
--
|
||||
CREATE DATABASE IF NOT EXISTS `b1evaluation` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
|
||||
USE `b1evaluation`;
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Table structure for table `passagers`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `passagers`;
|
||||
CREATE TABLE IF NOT EXISTS `passagers` (
|
||||
`id_passager` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`nom` varchar(255) NOT NULL,
|
||||
`prenom` varchar(255) NOT NULL,
|
||||
`age` int(11) NOT NULL,
|
||||
`siege` varchar(4) NOT NULL,
|
||||
`vol_id` int(11) NOT NULL,
|
||||
PRIMARY KEY (`id_passager`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
|
||||
|
||||
--
|
||||
-- Dumping data for table `passagers`
|
||||
--
|
||||
|
||||
INSERT INTO `passagers` (`id_passager`, `nom`, `prenom`, `age`, `siege`, `vol_id`) VALUES
|
||||
(1, 'Welma', 'Roucier', 68, 'b047', 1);
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Table structure for table `vol`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `vol`;
|
||||
CREATE TABLE IF NOT EXISTS `vol` (
|
||||
`id_vol` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`de` varchar(255) NOT NULL,
|
||||
`a` varchar(255) NOT NULL,
|
||||
`via` varchar(255) NOT NULL,
|
||||
`places` int(11) NOT NULL,
|
||||
`reservations` int(11) NOT NULL,
|
||||
PRIMARY KEY (`id_vol`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
|
||||
|
||||
--
|
||||
-- Dumping data for table `vol`
|
||||
--
|
||||
|
||||
INSERT INTO `vol` (`id_vol`, `de`, `a`, `via`, `places`, `reservations`) VALUES
|
||||
(1, 'Prague', 'Cork', 'Rennes', 25, 11);
|
||||
COMMIT;
|
||||
|
||||
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
|
||||
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
|
||||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
@ -0,0 +1,15 @@
|
||||
# si le module mod-rewrite est activé
|
||||
<IfModule mod_rewrite.c>
|
||||
# init du moteur
|
||||
RewriteEngine On
|
||||
# url de départ de l'api
|
||||
RewriteBase /
|
||||
# si ce n'est pas index.php
|
||||
RewriteRule ^index\.php$ - [L]
|
||||
# si le fichier existe pas
|
||||
RewriteCond %{REQUEST_FILENAME} !-f
|
||||
# si le dossier existe pas
|
||||
RewriteCond %{REQUEST_FILENAME} !-d
|
||||
# je renvoie vers l'index de lapi
|
||||
RewriteRule . /b1api/index.php [L]
|
||||
</IfModule>
|
@ -0,0 +1 @@
|
||||
# API
|
@ -0,0 +1,24 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>jQuery Query</title>
|
||||
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
//alert('ok');
|
||||
$.get("http://localhost/b1api/vol/liste", function(data, status){
|
||||
console.log(data);
|
||||
alert
|
||||
(
|
||||
"Vol : " + data.id_vol
|
||||
+ "\n de : " + data.de
|
||||
);
|
||||
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,17 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Réservation (saisie)</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Réserver pour ?</h1>
|
||||
<form action="test-post" method="POST">
|
||||
<label for="nom">Nom :</label><input type="text" name="nom" id="nom"/>
|
||||
<br/><label for="prenom">Prénom :</label><input type="text" name="prenom" id="prenom"/>
|
||||
<br/><label for="infos">Informations particulières ?</label>
|
||||
<br/><textarea name="infos" id="infos"></textarea>
|
||||
<br/><button type="submit" name="action" value="BOOK">Réserver</button>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,30 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Appel de l'API en CURL</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>APPEL de l'adresse http://localhost/b1api/vol/liste</h1>
|
||||
<?php
|
||||
//
|
||||
$api_url = "http://localhost/b1api/vol/liste";
|
||||
$curl = curl_init($api_url);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||
$response_json = curl_exec($curl);
|
||||
curl_close($curl);
|
||||
$ligne_de_resultat = json_decode($response_json);
|
||||
//print_r($response_json);
|
||||
//print_r($ligne_de_resultat);
|
||||
|
||||
|
||||
echo "<h2>Vol n°" . $ligne_de_resultat->id_vol . "</h2>";
|
||||
echo "<dl>";
|
||||
echo "<dt>de</dt><dd>" . $ligne_de_resultat->de . "</dd>";
|
||||
echo "<dt>à</dt><dd>" . $ligne_de_resultat->a . "</dd>";
|
||||
echo "<dt>via</dt><dd>" . $ligne_de_resultat->via . "</dd>";
|
||||
echo "<dt>Places restantes</dt><dd>" . ($ligne_de_resultat->places - $ligne_de_resultat->reservations) . "</dd>";
|
||||
echo "</dl>";
|
||||
?>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
header('Content-type: application/json;charset=utf-8');
|
||||
//phpinfo();
|
||||
if($_SERVER['REQUEST_METHOD'] === "GET")
|
||||
{
|
||||
if(preg_match("/^\/b1api\/vol\/liste/",$_SERVER['REDIRECT_URL']))
|
||||
{
|
||||
$mysqli = new mysqli("localhost", "root", "", "b1eval");
|
||||
if ($mysqli->connect_errno) {
|
||||
header('HTTP/1.1 500 OK');
|
||||
echo json_encode( array('erreur mysql' => "Échec lors de la connexion à MySQL : (" . $mysqli->connect_errno . ") " . $mysqli->connect_error));
|
||||
}
|
||||
else {
|
||||
$resultat = $mysqli->query('SELECT * FROM `vol`');
|
||||
$ligne_de_resultat = $resultat->fetch_array(MYSQLI_ASSOC);
|
||||
header('HTTP/1.1 200 OK');
|
||||
echo json_encode( $ligne_de_resultat);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
header('HTTP/1.1 404 OK');
|
||||
echo json_encode( array('erreur' => "route inconnue ".$_SERVER['REQUEST_URI']) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
header('HTTP/1.1 404 OK');
|
||||
echo json_encode( array('erreur' => "METHODE NON SUPPORTEE : ".$_SERVER['REQUEST_METHOD']));
|
||||
}
|
Loading…
Reference in new issue