-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapiRest.php
More file actions
33 lines (25 loc) · 716 Bytes
/
apiRest.php
File metadata and controls
33 lines (25 loc) · 716 Bytes
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
<?php
/**
* Web Service RESTful en PHP con MySQL (CRUD)
* *
* @author Dashy76
* @link https://github.com/Dashy76/web_service_php.git
*/
require "conexionApi.php";
$conexion = new Conexion();
$pdo = $conexion ->obtenerConexion();
//listar registro y consultar registro
if ($_SERVER["REQUEST_METHOD"] == "GET"){
$sql = "SELECT * FROM tb_usuario";
$params = [];
if (isset($_GET["id"])) {
$sql .= "WHERE id=:id";
$params[":id"] = $_GET ["id"];
}
$stmt = $pdo->prepare($sql);
$stmt->execute($params);
$stmt->setFetchMode(PDO::FETCH_ASSOC);
header("HTTP/1.1 200-ok");
echo json_encode($stmt->fetchAll());
exit;
}