-
Notifications
You must be signed in to change notification settings - Fork 0
/
data.php
47 lines (37 loc) · 1.3 KB
/
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
<?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 applications and versions from the database
$sql = "SELECT DISTINCT application FROM applications";
$stmt = $conn->prepare($sql);
$stmt->execute();
$applications = $stmt->fetchAll(PDO::FETCH_COLUMN);
$data = [];
foreach ($applications as $application) {
$appData = ['application' => $application, 'versions' => []];
$sql = "SELECT version, run FROM applications WHERE application = :application";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':application', $application);
$stmt->execute();
$versions = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($versions as $version) {
$appData['versions'][] = $version;
}
$data[] = $appData;
}
// Convert data to JSON and send the response
header('Content-Type: application/json');
echo json_encode($data);
} catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
// Close the database connection
$conn = null;
?>