-
Notifications
You must be signed in to change notification settings - Fork 0
/
add_data.php
35 lines (28 loc) · 961 Bytes
/
add_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
<?php
// Database configuration
$host = 'localhost';
$username = 'root';
$password = 'Qw3rty123?';
$database = 'devopsdev';
// Create a new database connection
$conn = new mysqli($host, $username, $password, $database);
// Check the connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Retrieve the data from the request body
$data = json_decode(file_get_contents('php://input'), true);
// Insert the new data into the database
$sql = "INSERT INTO applications (application, version, run) VALUES (?, ?, ?)";
$stmt = $conn->prepare($sql);
$stmt->bind_param('sss', $data['application'], $data['version'], $data['run']);
$stmt->execute();
// Get the ID of the newly inserted row
$insertId = $stmt->insert_id;
// Close the database connection
$stmt->close();
$conn->close();
// Return the ID of the newly inserted row as JSON
header('Content-Type: application/json');
echo json_encode(array('id' => $insertId));
?>