update
This commit is contained in:
@@ -16,8 +16,10 @@ if ($type == "get_npm_sqlite_data") {
|
||||
// Fetch the last 30 records
|
||||
$stmt = $db->query("SELECT timestamp, PM1, PM25, PM10 FROM data ORDER BY timestamp DESC LIMIT 30");
|
||||
$data = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$reversedData = array_reverse($data); // Reverse the order
|
||||
|
||||
|
||||
echo json_encode($data);
|
||||
echo json_encode($reversedData);
|
||||
} catch (PDOException $e) {
|
||||
echo json_encode(["error" => $e->getMessage()]);
|
||||
}
|
||||
@@ -94,50 +96,50 @@ if ($type == "clear_loopLogs") {
|
||||
|
||||
if ($type == "database_size") {
|
||||
|
||||
// Path to the SQLite database file
|
||||
$databasePath = '/var/www/nebuleair_pro_4g/sqlite/sensors.db';
|
||||
// Path to the SQLite database file
|
||||
$databasePath = '/var/www/nebuleair_pro_4g/sqlite/sensors.db';
|
||||
|
||||
// Check if the file exists
|
||||
if (file_exists($databasePath)) {
|
||||
try {
|
||||
// Connect to the SQLite database
|
||||
$db = new PDO("sqlite:$databasePath");
|
||||
// Check if the file exists
|
||||
if (file_exists($databasePath)) {
|
||||
try {
|
||||
// Connect to the SQLite database
|
||||
$db = new PDO("sqlite:$databasePath");
|
||||
|
||||
// Get the file size in bytes
|
||||
$fileSizeBytes = filesize($databasePath);
|
||||
// Get the file size in bytes
|
||||
$fileSizeBytes = filesize($databasePath);
|
||||
|
||||
// Convert the file size to human-readable formats
|
||||
$fileSizeKilobytes = $fileSizeBytes / 1024; // KB
|
||||
$fileSizeMegabytes = $fileSizeKilobytes / 1024; // MB
|
||||
// Convert the file size to human-readable formats
|
||||
$fileSizeKilobytes = $fileSizeBytes / 1024; // KB
|
||||
$fileSizeMegabytes = $fileSizeKilobytes / 1024; // MB
|
||||
|
||||
// Query the number of records in the `data` table
|
||||
$query = "SELECT COUNT(*) AS total_records FROM data";
|
||||
$result = $db->query($query);
|
||||
$recordCount = $result ? $result->fetch(PDO::FETCH_ASSOC)['total_records'] : 0;
|
||||
// Query the number of records in the `data` table
|
||||
$query = "SELECT COUNT(*) AS total_records FROM data";
|
||||
$result = $db->query($query);
|
||||
$recordCount = $result ? $result->fetch(PDO::FETCH_ASSOC)['total_records'] : 0;
|
||||
|
||||
// Prepare the JSON response
|
||||
$data = [
|
||||
'path' => $databasePath,
|
||||
'size_bytes' => $fileSizeBytes,
|
||||
'size_kilobytes' => round($fileSizeKilobytes, 2),
|
||||
'size_megabytes' => round($fileSizeMegabytes, 2),
|
||||
'data_table_records' => $recordCount
|
||||
];
|
||||
// Prepare the JSON response
|
||||
$data = [
|
||||
'path' => $databasePath,
|
||||
'size_bytes' => $fileSizeBytes,
|
||||
'size_kilobytes' => round($fileSizeKilobytes, 2),
|
||||
'size_megabytes' => round($fileSizeMegabytes, 2),
|
||||
'data_table_records' => $recordCount
|
||||
];
|
||||
|
||||
// Output the JSON response
|
||||
echo json_encode($data, JSON_PRETTY_PRINT);
|
||||
} catch (PDOException $e) {
|
||||
// Handle database connection errors
|
||||
// Output the JSON response
|
||||
echo json_encode($data, JSON_PRETTY_PRINT);
|
||||
} catch (PDOException $e) {
|
||||
// Handle database connection errors
|
||||
echo json_encode([
|
||||
'error' => 'Database query failed: ' . $e->getMessage()
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
// Handle error if the file doesn't exist
|
||||
echo json_encode([
|
||||
'error' => 'Database query failed: ' . $e->getMessage()
|
||||
'error' => 'Database file not found',
|
||||
'path' => $databasePath
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
// Handle error if the file doesn't exist
|
||||
echo json_encode([
|
||||
'error' => 'Database file not found',
|
||||
'path' => $databasePath
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user