-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathread.php
More file actions
47 lines (36 loc) · 1.13 KB
/
read.php
File metadata and controls
47 lines (36 loc) · 1.13 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
<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
include_once '../config/database.php';
include_once '../class/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,
"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.")
);
}
?>