-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfetch_data.php
53 lines (43 loc) · 1.4 KB
/
fetch_data.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
<?php
$servername = "localhost";
$username = "root";
$password = "Qw3rty123?";
$dbname = "devopsdev";
// Create a new PDO object
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
// Set PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
try {
// Retrieve application data
$sql = "SELECT application, version, run FROM applications";
$stmt = $conn->prepare($sql);
$stmt->execute();
$applications = $stmt->fetchAll(PDO::FETCH_ASSOC);
// Group applications by name
$groupedApplications = [];
foreach ($applications as $app) {
$application = $app['application'];
$version = $app['version'];
$run = $app['run'];
if (!isset($groupedApplications[$application])) {
$groupedApplications[$application] = [
'application' => $application,
'versions' => [],
'run' => $run
];
}
$groupedApplications[$application]['versions'][] = [
'version' => $version
];
}
// Convert the grouped applications to a simple array
$result = array_values($groupedApplications);
// Return the result as JSON
header('Content-Type: application/json');
echo json_encode($result);
} catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
// Close the database connection
$conn = null;
?>