-
Notifications
You must be signed in to change notification settings - Fork 0
/
read.php
38 lines (35 loc) · 976 Bytes
/
read.php
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
<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
include_once 'database.php';
include_once 'employees.php';
$database = new Database();
$db = $database->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,
"phone" => $phone,
"address" => $address
);
array_push($employeeArr["body"], $e);
}
echo json_encode($employeeArr);
}
else{
http_response_code(404);
echo json_encode(
array("message" => "No record found.")
);
}
?>