From 61d3555794faf43fa92321655c2c9d8c5d80b13f Mon Sep 17 00:00:00 2001 From: jlospino Date: Sat, 26 Feb 2022 23:27:02 -0500 Subject: [PATCH 1/3] api servi-express en php --- README.md | 22 +-- api/create.php | 63 ++++---- api/delete.php | 26 ++-- api/read.php | 96 ++++++------ api/single_read.php | 39 ----- api/update.php | 34 +++-- class/employees.php | 345 +++++++++++++++++++++++++------------------- config/database.php | 42 +++--- 8 files changed, 348 insertions(+), 319 deletions(-) delete mode 100644 api/single_read.php diff --git a/README.md b/README.md index 3ed10b6..f285a81 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ -# php-rest-api -This is a step by step PHP 7 & MySQL REST API tutorial, In this tutorial i am going to share with you how to create a PHP 7 CRUD (Create, Read, Update, Delete) RESTful API with MySQL database. - -[Create Simple PHP 7 CRUD REST API with MySQL & PHP PDO](https://www.positronx.io/create-simple-php-crud-rest-api-with-mysql-php-pdo/) - -## PHP CRUD API -* `GET - http://localhost:8080/api/read.php` Fetch ALL Records -* `GET - localhost:8080/api/single_read.php/?id=2` Fetch Single Record -* `POST - http://localhost:8080/api/create.php` Create Record -* `POST - http://localhost:8080/api/update.php` Update Record -* `DELETE - localhost:8080/api/delete.php` Remove Records +# php-rest-api +This is a step by step PHP 7 & MySQL REST API tutorial, In this tutorial i am going to share with you how to create a PHP 7 CRUD (Create, Read, Update, Delete) RESTful API with MySQL database. + +[Create Simple PHP 7 CRUD REST API with MySQL & PHP PDO](https://www.positronx.io/create-simple-php-crud-rest-api-with-mysql-php-pdo/) + +## PHP CRUD API +* `GET - http://localhost:8080/api/read.php` Fetch ALL Records +* `GET - localhost:8080/api/single_read.php/?id=2` Fetch Single Record +* `POST - http://localhost:8080/api/create.php` Create Record +* `POST - http://localhost:8080/api/update.php` Update Record +* `DELETE - localhost:8080/api/delete.php` Remove Records diff --git a/api/create.php b/api/create.php index 7422f30..56b17c1 100644 --- a/api/create.php +++ b/api/create.php @@ -1,29 +1,34 @@ -getConnection(); - - $item = new Employee($db); - - $data = json_decode(file_get_contents("php://input")); - - $item->name = $data->name; - $item->email = $data->email; - $item->age = $data->age; - $item->designation = $data->designation; - $item->created = date('Y-m-d H:i:s'); - - if($item->createEmployee()){ - echo 'Employee created successfully.'; - } else{ - echo 'Employee could not be created.'; - } -?> \ No newline at end of file +getConnection(); + + $item = new Employee($db); + + $data = json_decode(file_get_contents("php://input")); + + + $item->id_reservations = $data->id_reservations; + $item->id_users = $data->id_users; + $item->lugar_inicio = $data->lugar_inicio; + $item->lugar_destino = $data->lugar_destino; + $item->cupos = $data->cupos; + $item->id_drivers = $data->id_drivers; + $item->censo_drivers = $data->censo_drivers; + $item->placa_drivers = $data->placa_drivers; + $item->fecha = date('Y-m-d H:i:s'); + if($item->createEmployee()){ + echo 'created successfully.'; + } else{ + echo 'could not be created.'; + } + + diff --git a/api/delete.php b/api/delete.php index 99ddcb6..d2844c8 100644 --- a/api/delete.php +++ b/api/delete.php @@ -4,22 +4,30 @@ header("Access-Control-Allow-Methods: POST"); header("Access-Control-Max-Age: 3600"); header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With"); - + include_once '../config/database.php'; include_once '../class/employees.php'; - + $database = new Database(); $db = $database->getConnection(); - + $item = new Employee($db); - + $data = json_decode(file_get_contents("php://input")); + - $item->id = $data->id; - + $item->id_reservations = $data->id_reservations; + $item->id_users = $data->id_users; + $item->lugar_inicio = $data->lugar_inicio; + $item->lugar_destino = $data->lugar_destino; + $item->cupos = $data->cupos; + $item->id_drivers = $data->id_drivers; + $item->censo_drivers = $data->censo_drivers; + $item->placa_drivers = $data->placa_drivers; + $item->fecha = date('Y-m-d H:i:s'); if($item->deleteEmployee()){ - echo json_encode("Employee deleted."); + echo 'delete successfully.'; } else{ - echo json_encode("Data could not be deleted"); + echo 'could not be created.'; } -?> \ No newline at end of file + diff --git a/api/read.php b/api/read.php index cbc06d2..3270619 100644 --- a/api/read.php +++ b/api/read.php @@ -1,47 +1,49 @@ -getConnection(); - - $items = new Employee($db); - - $stmt = $items->getEmployees(); - $itemCount = $stmt->rowCount(); - - - echo json_encode($itemCount); - - if($itemCount > 0){ - - $employeeArr = array(); - $employeeArr["body"] = array(); - $employeeArr["itemCount"] = $itemCount; - - while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){ - extract($row); - $e = array( - "id" => $id, - "name" => $name, - "email" => $email, - "age" => $age, - "designation" => $designation, - "created" => $created - ); - - array_push($employeeArr["body"], $e); - } - echo json_encode($employeeArr); - } - - else{ - http_response_code(404); - echo json_encode( - array("message" => "No record found.") - ); - } -?> \ No newline at end of file +getConnection(); + + $items = new Employee($db); + + $stmt = $items->getEmployees(); + $itemCount = $stmt->rowCount(); + + + + + if($itemCount > 0){ + + $employeeArr = array(); + + + + while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){ + extract($row); + $e = array( + "id_reservations" => $id_reservations, + "cliente" => $nombre, + "lugar_inicio" => $lugar_inicio, + "lugar_destino" => $lugar_destino, + "cupos" => $cupos, + "conductor" => $nombre, + "censo" => $censo, + "placa" => $placa, + "fecha" => $fecha + ); + + array_push($employeeArr, $e); + } + echo json_encode($employeeArr); + } + + else{ + http_response_code(404); + echo json_encode( + array("message" => "No record found." ) + ); + } diff --git a/api/single_read.php b/api/single_read.php deleted file mode 100644 index c79e96e..0000000 --- a/api/single_read.php +++ /dev/null @@ -1,39 +0,0 @@ -getConnection(); - - $item = new Employee($db); - - $item->id = isset($_GET['id']) ? $_GET['id'] : die(); - - $item->getSingleEmployee(); - - if($item->name != null){ - // create array - $emp_arr = array( - "id" => $item->id, - "name" => $item->name, - "email" => $item->email, - "age" => $item->age, - "designation" => $item->designation, - "created" => $item->created - ); - - http_response_code(200); - echo json_encode($emp_arr); - } - - else{ - http_response_code(404); - echo json_encode("Employee not found."); - } -?> \ No newline at end of file diff --git a/api/update.php b/api/update.php index abcce1d..c06cd7d 100644 --- a/api/update.php +++ b/api/update.php @@ -4,29 +4,31 @@ header("Access-Control-Allow-Methods: POST"); header("Access-Control-Max-Age: 3600"); header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With"); - + include_once '../config/database.php'; include_once '../class/employees.php'; - + $database = new Database(); $db = $database->getConnection(); - + $item = new Employee($db); - + $data = json_decode(file_get_contents("php://input")); + - $item->id = $data->id; - - // employee values - $item->name = $data->name; - $item->email = $data->email; - $item->age = $data->age; - $item->designation = $data->designation; - $item->created = date('Y-m-d H:i:s'); - + $item->id_reservations = $data->id_reservations; + $item->id_users = $data->id_users; + $item->lugar_inicio = $data->lugar_inicio; + $item->lugar_destino = $data->lugar_destino; + $item->cupos = $data->cupos; + $item->id_drivers = $data->id_drivers; + $item->censo_drivers = $data->censo_drivers; + $item->placa_drivers = $data->placa_drivers; + $item->fecha = date('Y-m-d H:i:s'); if($item->updateEmployee()){ - echo json_encode("Employee data updated."); + echo 'update successfully.'; } else{ - echo json_encode("Data could not be updated"); + echo 'could not be created.'; } -?> \ No newline at end of file + + diff --git a/class/employees.php b/class/employees.php index e85a02a..707431d 100644 --- a/class/employees.php +++ b/class/employees.php @@ -1,147 +1,198 @@ -conn = $db; - } - - // GET ALL - public function getEmployees(){ - $sqlQuery = "SELECT id, name, email, age, designation, created FROM " . $this->db_table . ""; - $stmt = $this->conn->prepare($sqlQuery); - $stmt->execute(); - return $stmt; - } - - // CREATE - public function createEmployee(){ - $sqlQuery = "INSERT INTO - ". $this->db_table ." - SET - name = :name, - email = :email, - age = :age, - designation = :designation, - created = :created"; - - $stmt = $this->conn->prepare($sqlQuery); - - // sanitize - $this->name=htmlspecialchars(strip_tags($this->name)); - $this->email=htmlspecialchars(strip_tags($this->email)); - $this->age=htmlspecialchars(strip_tags($this->age)); - $this->designation=htmlspecialchars(strip_tags($this->designation)); - $this->created=htmlspecialchars(strip_tags($this->created)); - - // bind data - $stmt->bindParam(":name", $this->name); - $stmt->bindParam(":email", $this->email); - $stmt->bindParam(":age", $this->age); - $stmt->bindParam(":designation", $this->designation); - $stmt->bindParam(":created", $this->created); - - if($stmt->execute()){ - return true; - } - return false; - } - - // UPDATE - public function getSingleEmployee(){ - $sqlQuery = "SELECT - id, - name, - email, - age, - designation, - created - FROM - ". $this->db_table ." - WHERE - id = ? - LIMIT 0,1"; - - $stmt = $this->conn->prepare($sqlQuery); - - $stmt->bindParam(1, $this->id); - - $stmt->execute(); - - $dataRow = $stmt->fetch(PDO::FETCH_ASSOC); - - $this->name = $dataRow['name']; - $this->email = $dataRow['email']; - $this->age = $dataRow['age']; - $this->designation = $dataRow['designation']; - $this->created = $dataRow['created']; - } - - // UPDATE - public function updateEmployee(){ - $sqlQuery = "UPDATE - ". $this->db_table ." - SET - name = :name, - email = :email, - age = :age, - designation = :designation, - created = :created - WHERE - id = :id"; - - $stmt = $this->conn->prepare($sqlQuery); - - $this->name=htmlspecialchars(strip_tags($this->name)); - $this->email=htmlspecialchars(strip_tags($this->email)); - $this->age=htmlspecialchars(strip_tags($this->age)); - $this->designation=htmlspecialchars(strip_tags($this->designation)); - $this->created=htmlspecialchars(strip_tags($this->created)); - $this->id=htmlspecialchars(strip_tags($this->id)); - - // bind data - $stmt->bindParam(":name", $this->name); - $stmt->bindParam(":email", $this->email); - $stmt->bindParam(":age", $this->age); - $stmt->bindParam(":designation", $this->designation); - $stmt->bindParam(":created", $this->created); - $stmt->bindParam(":id", $this->id); - - if($stmt->execute()){ - return true; - } - return false; - } - - // DELETE - function deleteEmployee(){ - $sqlQuery = "DELETE FROM " . $this->db_table . " WHERE id = ?"; - $stmt = $this->conn->prepare($sqlQuery); - - $this->id=htmlspecialchars(strip_tags($this->id)); - - $stmt->bindParam(1, $this->id); - - if($stmt->execute()){ - return true; - } - return false; - } - - } -?> - +conn = $db; + } + + // GET ALL SELECT id_reservations, u.nombre,lugar_inicio, lugar_destino,cupos,d.nombre,d.placa, d.censo,fecha FROM reservations r JOIN drivers d ON r.id_drivers=d.id_dirvers JOIN users u on r.id_users=u.id_users + public function getEmployees() + { + $sqlQuery = "SELECT id_reservations, u.nombre,lugar_inicio, lugar_destino,cupos,d.nombre,d.placa, d.censo,fecha FROM reservations r JOIN drivers d ON r.id_drivers=d.id_dirvers JOIN users u on r.id_users=u.id_users"; + $stmt = $this->conn->prepare($sqlQuery); + $stmt->execute(); + return $stmt; + + } + + // CREATE + public function createEmployee() + { + + + + $sqlQuery = "INSERT INTO + " . $this->db_table . + + " + SET + + id_users = :id_users, + lugar_inicio = :lugar_inicio, + lugar_destino = :lugar_destino, + cupos = :cupos, + fecha = :fecha"; + + //dejamos afuera los demas campos por que van null por defaul, ya que no tendran asignacion de chofer por el momento. + + $stmt = $this->conn->prepare($sqlQuery); + + // sanitize + $this->id_reservations = htmlspecialchars(strip_tags($this->id_reservations)); + $this->id_users = htmlspecialchars(strip_tags($this->id_users)); + $this->lugar_inicio = htmlspecialchars(strip_tags($this->lugar_inicio)); + $this->lugar_destino = htmlspecialchars(strip_tags($this->lugar_inicio)); + $this->cupos = htmlspecialchars(strip_tags($this->cupos)); + $this->id_drivers = htmlspecialchars(strip_tags($this->id_drivers)); + $this->censo_drivers = htmlspecialchars(strip_tags($this->censo_drivers)); + $this->placa_drivers = htmlspecialchars(strip_tags($this->placa_drivers)); + $this->fecha = htmlspecialchars(strip_tags($this->fecha)); + + + // bind data + + + // $stmt->bindParam(":id_reservations", $this->id_reservations); + $stmt->bindParam(":id_users", $this->id_users); + $stmt->bindParam(":lugar_inicio", $this->lugar_inicio); + $stmt->bindParam(":lugar_destino", $this->lugar_destino); + $stmt->bindParam(":cupos", $this->cupos); + /* $stmt->bindParam(":id_drivers", $this->id_drivers); + $stmt->bindParam(":censo_drivers", $this->censo_drivers); + $stmt->bindParam(":placa_drivers", $this->placa_drivers);*/ + $stmt->bindParam(":fecha", $this->fecha); + if ($stmt->execute()) { + return true; + } + return false; + } + + + + // UPDATE + public function updateEmployee() + { + + /* "INSERT INTO + " . $this->db_table . + + " + SET + + id_users = :id_users, + lugar_inicio = :lugar_inicio, + lugar_destino = :lugar_destino, + cupos = :cupos, + fecha = :fecha"; + + //dejamos afuera los demas campos por que van null por defaul, ya que no tendran asignacion de chofer por el momento. */ + + + $sqlQuery = "UPDATE + " . $this->db_table . + + " + SET + + id_drivers = :id_drivers, + censo_drivers = :censo_drivers, + placa_drivers = :placa_drivers where id_reservations = :id_reservations"; + + $stmt = $this->conn->prepare($sqlQuery); + + // sanitize + $this->id_reservations = htmlspecialchars(strip_tags($this->id_reservations)); + $this->id_users = htmlspecialchars(strip_tags($this->id_users)); + $this->lugar_inicio = htmlspecialchars(strip_tags($this->lugar_inicio)); + $this->lugar_destino = htmlspecialchars(strip_tags($this->lugar_inicio)); + $this->cupos = htmlspecialchars(strip_tags($this->cupos)); + $this->id_drivers = htmlspecialchars(strip_tags($this->id_drivers)); + $this->censo_drivers = htmlspecialchars(strip_tags($this->censo_drivers)); + $this->placa_drivers = htmlspecialchars(strip_tags($this->placa_drivers)); + $this->fecha = htmlspecialchars(strip_tags($this->fecha)); + + + // bind data + + + $stmt->bindParam(":id_reservations", $this->id_reservations); + /*$stmt->bindParam(":id_users", $this->id_users); + $stmt->bindParam(":lugar_inicio", $this->lugar_inicio); + $stmt->bindParam(":lugar_destino", $this->lugar_destino); + $stmt->bindParam(":cupos", $this->cupos);*/ + $stmt->bindParam(":id_drivers", $this->id_drivers); + $stmt->bindParam(":censo_drivers", $this->censo_drivers); + $stmt->bindParam(":placa_drivers", $this->placa_drivers); + // $stmt->bindParam(":fecha", $this->fecha); + if ($stmt->execute()) { + return true; + } + return false; + } + // DELETE + public function deleteEmployee() + { + + + + $sqlQuery = "DELETE FROM + " . $this->db_table . + + " where id_reservations = :id_reservations"; + + $stmt = $this->conn->prepare($sqlQuery); + + // sanitize + $this->id_reservations = htmlspecialchars(strip_tags($this->id_reservations)); + $this->id_users = htmlspecialchars(strip_tags($this->id_users)); + $this->lugar_inicio = htmlspecialchars(strip_tags($this->lugar_inicio)); + $this->lugar_destino = htmlspecialchars(strip_tags($this->lugar_inicio)); + $this->cupos = htmlspecialchars(strip_tags($this->cupos)); + $this->id_drivers = htmlspecialchars(strip_tags($this->id_drivers)); + $this->censo_drivers = htmlspecialchars(strip_tags($this->censo_drivers)); + $this->placa_drivers = htmlspecialchars(strip_tags($this->placa_drivers)); + $this->fecha = htmlspecialchars(strip_tags($this->fecha)); + + + // bind data + + + $stmt->bindParam(":id_reservations", $this->id_reservations); + /*$stmt->bindParam(":id_users", $this->id_users); + $stmt->bindParam(":lugar_inicio", $this->lugar_inicio); + $stmt->bindParam(":lugar_destino", $this->lugar_destino); + $stmt->bindParam(":cupos", $this->cupos); + $stmt->bindParam(":id_drivers", $this->id_drivers); + $stmt->bindParam(":censo_drivers", $this->censo_drivers); + $stmt->bindParam(":placa_drivers", $this->placa_drivers); + $stmt->bindParam(":fecha", $this->fecha); */ + if ($stmt->execute()) { + return true; + } + return false; + } + + +} diff --git a/config/database.php b/config/database.php index 8359b6f..9b9a0ee 100644 --- a/config/database.php +++ b/config/database.php @@ -1,21 +1,21 @@ -conn = null; - try{ - $this->conn = new PDO("mysql:host=" . $this->host . ";dbname=" . $this->database_name, $this->username, $this->password); - $this->conn->exec("set names utf8"); - }catch(PDOException $exception){ - echo "Database could not be connected: " . $exception->getMessage(); - } - return $this->conn; - } - } -?> \ No newline at end of file +conn = null; + try{ + $this->conn = new PDO("mysql:host=" . $this->host . ";dbname=" . $this->database_name, $this->username, $this->password); + $this->conn->exec("set names utf8"); + }catch(PDOException $exception){ + echo "Database could not be connected: " . $exception->getMessage(); + } + return $this->conn; + } + } +?> From c90d511dec330ca5f8995c275f125e37a55b15c3 Mon Sep 17 00:00:00 2001 From: jlospino Date: Sat, 26 Feb 2022 23:37:38 -0500 Subject: [PATCH 2/3] api --- mysql/servi-express.sql | 213 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 213 insertions(+) create mode 100644 mysql/servi-express.sql diff --git a/mysql/servi-express.sql b/mysql/servi-express.sql new file mode 100644 index 0000000..f8ed581 --- /dev/null +++ b/mysql/servi-express.sql @@ -0,0 +1,213 @@ +-- phpMyAdmin SQL Dump +-- version 5.1.0 +-- https://www.phpmyadmin.net/ +-- +-- Host: localhost +-- Generation Time: Feb 27, 2022 at 05:32 AM +-- Server version: 10.4.18-MariaDB +-- PHP Version: 7.4.16 + +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: `servi-express` +-- + +-- -------------------------------------------------------- + +-- +-- Table structure for table `admin` +-- + +CREATE TABLE `admin` ( + `id_admin` int(10) NOT NULL, + `correo` varchar(100) NOT NULL, + `password` varchar(100) NOT NULL, + `nombre` varchar(100) NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +-- -------------------------------------------------------- + +-- +-- Table structure for table `drivers` +-- + +CREATE TABLE `drivers` ( + `id_dirvers` int(10) NOT NULL, + `nombre` varchar(100) NOT NULL, + `placa` varchar(10) NOT NULL, + `censo` int(10) NOT NULL, + `imagen` varchar(1000) NOT NULL, + `password` varchar(100) NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +-- +-- Dumping data for table `drivers` +-- + +INSERT INTO `drivers` (`id_dirvers`, `nombre`, `placa`, `censo`, `imagen`, `password`) VALUES +(1124066926, 'juan david montoya', 'afc22a', 102, '', 'jlospino'), +(1124066936, 'jorge luis ospino', 'afc21b', 101, '', 'jlospino'); + +-- -------------------------------------------------------- + +-- +-- Table structure for table `evaluations` +-- + +CREATE TABLE `evaluations` ( + `id_drivers` int(10) NOT NULL, + `estrellas` int(1) NOT NULL, + `opinion` varchar(300) NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +-- +-- Dumping data for table `evaluations` +-- + +INSERT INTO `evaluations` (`id_drivers`, `estrellas`, `opinion`) VALUES +(1124066936, 4443, 'nn'); + +-- -------------------------------------------------------- + +-- +-- Table structure for table `reservations` +-- + +CREATE TABLE `reservations` ( + `id_reservations` int(10) NOT NULL, + `id_users` int(10) NOT NULL, + `lugar_inicio` varchar(100) NOT NULL, + `lugar_destino` varchar(100) NOT NULL, + `cupos` int(2) NOT NULL, + `id_drivers` int(10) DEFAULT NULL, + `censo_drivers` int(10) DEFAULT NULL, + `placa_drivers` varchar(100) DEFAULT NULL, + `fecha` datetime NOT NULL DEFAULT current_timestamp() +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +-- +-- Dumping data for table `reservations` +-- + +INSERT INTO `reservations` (`id_reservations`, `id_users`, `lugar_inicio`, `lugar_destino`, `cupos`, `id_drivers`, `censo_drivers`, `placa_drivers`, `fecha`) VALUES +(2, 112545555, 'calle 2', 'san martin', 3, 1124066926, 102, 'afc22a', '2022-02-20 21:11:51'), +(8, 12332233, 'sdffd', 'sdfsdf', 3, 1124066936, 101, 'afc21b', '2022-02-20 23:24:00'), +(9, 12332233, 'fh', 'dfhf', 3, 1124066936, 101, 'afc21b', '2022-02-20 23:24:31'), +(32, 112545555, 'santo domingo', 'santo domingo', 2, 1124066926, 102, 'afc22a', '2022-02-21 06:07:11'), +(98, 112545555, '', '', 2, 1124066926, 101, 'afc22a', '2022-02-20 23:29:45'), +(3254, 112545555, 'santo domingo', 'santo domingo', 2, NULL, NULL, NULL, '2022-02-22 02:49:57'), +(3454, 112545555, 'santo domingo', 'santo domingo', 2, 1124066926, 102, 'afc22a', '2022-02-22 02:36:25'), +(3455, 112545555, 'hkj', 'hbvi', 5, NULL, NULL, NULL, '2022-02-21 20:44:34'), +(3456, 12332233, 'jklj', 'guyyk', 1, NULL, NULL, NULL, '2022-02-21 20:45:22'), +(33332, 112545555, 'santo domingo', 'santo domingo', 2, NULL, NULL, NULL, '2022-02-22 02:50:14'), +(33333, 112545555, 'santo domingo', 'santo domingo', 2, NULL, NULL, NULL, '2022-02-22 02:52:33'), +(33335, 112545555, 'santo domingo', 'santo domingo', 2, NULL, NULL, NULL, '2022-02-22 02:52:47'), +(33336, 112545555, 'santo domingorr', 'santo domingorr', 2, NULL, NULL, NULL, '2022-02-22 02:52:50'), +(33337, 112545555, 'santo domingorr', 'santo domingorr', 2, NULL, NULL, NULL, '2022-02-22 02:52:54'), +(33338, 112545555, 'santo domingorr', 'santo domingorr', 4, NULL, NULL, NULL, '2022-02-22 02:52:59'), +(33339, 112545555, 'santo domingorr', 'santo domingorr', 4, NULL, NULL, NULL, '2022-02-22 03:00:05'); + +-- -------------------------------------------------------- + +-- +-- Table structure for table `users` +-- + +CREATE TABLE `users` ( + `id_users` int(10) NOT NULL, + `nombre` varchar(100) NOT NULL, + `correo` varchar(100) NOT NULL, + `password` varchar(100) NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +-- +-- Dumping data for table `users` +-- + +INSERT INTO `users` (`id_users`, `nombre`, `correo`, `password`) VALUES +(12332233, 'sebastian moreno', 'sebas@gmail.com', 'sebas123'), +(112545555, 'laura madrid orrego', 'laumadrid@gmail.com', 'laumadrid'); + +-- +-- Indexes for dumped tables +-- + +-- +-- Indexes for table `admin` +-- +ALTER TABLE `admin` + ADD PRIMARY KEY (`id_admin`); + +-- +-- Indexes for table `drivers` +-- +ALTER TABLE `drivers` + ADD PRIMARY KEY (`id_dirvers`) USING BTREE, + ADD UNIQUE KEY `censo` (`censo`), + ADD UNIQUE KEY `placa` (`placa`); + +-- +-- Indexes for table `evaluations` +-- +ALTER TABLE `evaluations` + ADD KEY `id_drivers` (`id_drivers`); + +-- +-- Indexes for table `reservations` +-- +ALTER TABLE `reservations` + ADD PRIMARY KEY (`id_reservations`), + ADD KEY `id_drivers` (`id_drivers`), + ADD KEY `nombre` (`id_users`), + ADD KEY `id_users` (`id_users`), + ADD KEY `censo_drivers` (`censo_drivers`), + ADD KEY `placa_dirvers` (`placa_drivers`); + +-- +-- Indexes for table `users` +-- +ALTER TABLE `users` + ADD PRIMARY KEY (`id_users`) USING BTREE; + +-- +-- AUTO_INCREMENT for dumped tables +-- + +-- +-- AUTO_INCREMENT for table `reservations` +-- +ALTER TABLE `reservations` + MODIFY `id_reservations` int(10) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=33341; + +-- +-- Constraints for dumped tables +-- + +-- +-- Constraints for table `evaluations` +-- +ALTER TABLE `evaluations` + ADD CONSTRAINT `evaluations_ibfk_1` FOREIGN KEY (`id_drivers`) REFERENCES `drivers` (`id_dirvers`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- +-- Constraints for table `reservations` +-- +ALTER TABLE `reservations` + ADD CONSTRAINT `reservations_ibfk_1` FOREIGN KEY (`id_drivers`) REFERENCES `drivers` (`id_dirvers`) ON DELETE CASCADE ON UPDATE CASCADE, + ADD CONSTRAINT `reservations_ibfk_2` FOREIGN KEY (`id_users`) REFERENCES `users` (`id_users`) ON DELETE CASCADE ON UPDATE CASCADE, + ADD CONSTRAINT `reservations_ibfk_3` FOREIGN KEY (`placa_drivers`) REFERENCES `drivers` (`placa`) ON DELETE CASCADE ON UPDATE CASCADE, + ADD CONSTRAINT `reservations_ibfk_4` FOREIGN KEY (`censo_drivers`) REFERENCES `drivers` (`censo`) ON DELETE CASCADE ON UPDATE CASCADE; +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 */; From 3c467c0cb02fda04ab3adae51630bb217253c4c1 Mon Sep 17 00:00:00 2001 From: jlospino Date: Sat, 26 Feb 2022 23:44:41 -0500 Subject: [PATCH 3/3] api servi-express --- README.md | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 README.md diff --git a/README.md b/README.md deleted file mode 100644 index f285a81..0000000 --- a/README.md +++ /dev/null @@ -1,11 +0,0 @@ -# php-rest-api -This is a step by step PHP 7 & MySQL REST API tutorial, In this tutorial i am going to share with you how to create a PHP 7 CRUD (Create, Read, Update, Delete) RESTful API with MySQL database. - -[Create Simple PHP 7 CRUD REST API with MySQL & PHP PDO](https://www.positronx.io/create-simple-php-crud-rest-api-with-mysql-php-pdo/) - -## PHP CRUD API -* `GET - http://localhost:8080/api/read.php` Fetch ALL Records -* `GET - localhost:8080/api/single_read.php/?id=2` Fetch Single Record -* `POST - http://localhost:8080/api/create.php` Create Record -* `POST - http://localhost:8080/api/update.php` Update Record -* `DELETE - localhost:8080/api/delete.php` Remove Records