What are the advantages of storing uptime data in a database for analysis and reporting?

Storing uptime data in a database allows for easy retrieval, analysis, and reporting. This data can be used to identify trends, track performance over time, and troubleshoot any issues that may arise. By storing this data in a database, it can be easily queried and manipulated to generate reports or visualizations for monitoring purposes.

// Assuming you have a database connection established

// Insert uptime data into the database
$uptime = 99.5; // example uptime percentage
$stmt = $pdo->prepare("INSERT INTO uptime_data (uptime_percentage) VALUES (:uptime)");
$stmt->bindParam(':uptime', $uptime);
$stmt->execute();

// Retrieve uptime data from the database for analysis
$stmt = $pdo->query("SELECT * FROM uptime_data");
while ($row = $stmt->fetch()) {
    echo "Uptime Percentage: " . $row['uptime_percentage'] . "%<br>";
}