-
Notifications
You must be signed in to change notification settings - Fork 0
/
api-read-single.php
123 lines (86 loc) · 3.12 KB
/
api-read-single.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
header('Access-Control-Allow-Origin: *');
header('Content-Type: application/json');
$api_readSingle = new Class {
/**
* @var
* @property Initialized
* Defined read data from api
* @since 03.15.2022
**/
private $init;
public function __construct()
{
$this->php_wine('autoload');
$this->init = new PHPWineVanillaFlavour\Plugins\PHPCrud\Crud\Vanilla;
$this->vanilla_readSingle($this->init::FETCH);
}
// Request join query statements
private function join_query() : string {
return "SELECT fc.name as relastionship_name,
friend.friend_id,
friend.friend_category_id,
friend.name,
friend.email,
friend.relationship,
friend.created_at
FROM friends friend
LEFT JOIN friend_categories fc
ON friend.friend_category_id = fc.cat_id
WHERE friend.friend_id = {$_REQUEST['friend_id']}
LIMIT 0,1
";
}
// get all data through api
private function vanilla_readSingle( string $vanilla) : void {
// Request vanilla public connection
$this->init->wine_db();
// Validate database then Read wine
if( $this->init === false ) { die("ERROR: Could not connect. " . $this->init->connect_error); }
new PHPWineVanillaFlavour\Plugins\PHPCrud\Crud\Vanilla( $vanilla , '', [ 'mixed' => [ $this->join_query() ] ], function($api_posts_get) {
$post = array(); if( $api_posts_get ) {
foreach ($api_posts_get as $friend) {
$posts_model = array(
'friend_id' => $friend['friend_id'],
'name' => $friend['name'],
'email' => $friend['email'],
'relationship' => $friend['relationship'],
'friend_category_id' => $friend['friend_category_id'],
'relastionship_name' => $friend['relastionship_name']
);
array_push($post, $posts_model);
}
/**
* Incase reponsed code is 200 means okay!
**/
http_response_code(200);
// execute api read to the browser
echo json_encode($post);
} else {
/**
* Incase reponsed code is 404 or greater means no found data !
**/
http_response_code(404);
// execute api error message to the browser
echo json_encode(
array('message' => 'Have no post available')
);
}
return [];
});
// closed database connection read
$this->init->wine_db()->close();
}
private function php_wine(string $autoload) : void {
require dirname(__FILE__) . DIRECTORY_SEPARATOR .'vendor/' . $autoload.'.'.'php';
}
};
/**
*
* Would you like me to treat a cake and coffee ?
* Become a donor, Because with you! We can build more...
* Donate:
* GCash : +639650332900
* Paypal account: [email protected]
*
**/