-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
58 lines (45 loc) · 1.79 KB
/
Copy pathindex.php
File metadata and controls
58 lines (45 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
// require 'flight/Flight.php';
require 'flight/autoload.php';
Flight::register('db','PDO', array('mysql:host=localhost;dbname=api','root',''));
Flight::route('GET /alumnos', function () {
$sentencia = Flight::db()->prepare("SELECT * FROM ALUMNOS");
$sentencia->execute();
$datos = $sentencia->fetchAll();
Flight::json($datos);
});
Flight::route('POST /alumnos', function () {
$nombres = (Flight::request()->data->nombres);
$apellidos= (Flight::request()->data->apellidos);
$sentencia = Flight::db()->prepare("INSERT INTO ALUMNOS(NOMBRES, APELLIDOS) VALUES(?,?)");
$sentencia->bindParam(1,$nombres);
$sentencia->bindParam(2,$apellidos);
$sentencia->execute();
Flight::jsonp(["Se ha agregado el alumno "]);
});
Flight::route('DELETE /alumnos', function () {
$id = (Flight::request()->data->id);
$sentencia = Flight::db()->prepare("DELETE FROM ALUMNOS WHERE ID = ?");
$sentencia->bindParam(1,$id);
$sentencia->execute();
Flight::jsonp(["Se ha borrado el registro del alumno "]);
});
Flight::route('PUT /alumnos', function () {
$id = (Flight::request()->data->id);
$nombres = (Flight::request()->data->nombres);
$apellidos= (Flight::request()->data->apellidos);
$sentencia = Flight::db()->prepare("UPDATE ALUMNOS SET NOMBRES = ?, APELLIDOS= ? WHERE ID = ?");
$sentencia->bindParam(1,$nombres);
$sentencia->bindParam(2,$apellidos);
$sentencia->bindParam(3,$id);
$sentencia->execute();
Flight::jsonp(["Se ha actualizado el alumno "]);
});
Flight::route('GET /alumnos/@id', function ($id) {
$sentencia = Flight::db()->prepare("SELECT * FROM ALUMNOS WHERE ID = ?");
$sentencia->bindParam(1,$id);
$sentencia->execute();
$datos = $sentencia->fetchAll();
Flight::json($datos);
});
Flight::start();