add all files

This commit is contained in:
Rucus
2026-02-17 09:29:34 -06:00
parent b8c8d67c67
commit 782d203799
21925 changed files with 2433086 additions and 0 deletions

View File

@@ -0,0 +1,66 @@
<?php
declare(strict_types=1);
namespace Lasuca\SharedEndpoint;
use mysqli;
use RuntimeException;
/**
* Fetch the latest snapshot of all SCADA tags.
*
* @param array<string,string> $config Connection credentials map.
*
* @return array<int,array<string,mixed>> Normalised tag rows.
*/
function fetchLatestItems(array $config): array
{
$connection = new mysqli(
$config['host'],
$config['username'],
$config['password'],
$config['database']
);
if ($connection->connect_error) {
$message = 'MySQL connection failed: ' . $connection->connect_error;
throw new RuntimeException($message);
}
$query = <<<SQL
SELECT
ID,
Name,
ROUND(Value, 0) AS Value,
ROUND(Value, 1) AS RoundedValue1,
ROUND(Value, 2) AS RoundedValue2,
Timestamp
FROM items
ORDER BY ID ASC
SQL;
$result = $connection->query($query);
if ($result === false) {
$message = 'Query failed: ' . $connection->error;
$connection->close();
throw new RuntimeException($message);
}
$rows = [];
while ($row = $result->fetch_assoc()) {
$rows[] = [
'tagId' => (int) $row['ID'],
'name' => $row['Name'],
'value' => (float) $row['Value'],
'rounded1' => (float) $row['RoundedValue1'],
'rounded2' => (float) $row['RoundedValue2'],
'timestamp' => $row['Timestamp'],
];
}
$result->free();
$connection->close();
return $rows;
}