Registration working
This commit is contained in:
1 parent
7f93508eb3
commit
34593f7ea4
2 files changed
+52
-45
No files matched your search
@@ -97,24 +97,35 @@ class DB implements DBIface {
|
||||
}
|
||||
}
|
||||
|
||||
public function updateDevice($id, $deviceData) {
|
||||
$sql = "
|
||||
UPDATE devices
|
||||
SET id = :id,
|
||||
mac_address = :mac_address,
|
||||
ip_address = :ip_address,
|
||||
ip_address_seen = :ip_address_seen,
|
||||
firmware_version = :firmware_version,
|
||||
temperature_offset = :temperature_offset,
|
||||
humidity_offset = :humidity_offset,
|
||||
last_seen = :last_seen
|
||||
WHERE id = :id
|
||||
";
|
||||
try {
|
||||
$stmt = $this->pdo->prepare($sql);
|
||||
$deviceData['id'] = $id;
|
||||
$stmt->execute($deviceData);
|
||||
return $stmt->rowCount();
|
||||
public function updateDevice($id, $deviceData) {
|
||||
// Start building the SQL query
|
||||
$sql = "UPDATE devices SET ";
|
||||
|
||||
// Add the columns to be updated
|
||||
$columns = [];
|
||||
foreach ($deviceData as $column => $value) {
|
||||
$columns[] = "$column = :$column";
|
||||
}
|
||||
$sql .= implode(", ", $columns);
|
||||
|
||||
// Add the WHERE clause based on id
|
||||
$sql .= " WHERE id = :id";
|
||||
|
||||
try {
|
||||
// Prepare the statement
|
||||
$stmt = $this->pdo->prepare($sql);
|
||||
|
||||
// Bind the parameters for the columns to be updated
|
||||
foreach ($deviceData as $column => $value) {
|
||||
$stmt->bindValue(":$column", $value);
|
||||
}
|
||||
|
||||
// Bind the parameter for the id
|
||||
$stmt->bindValue(":id", $id, PDO::PARAM_INT);
|
||||
|
||||
// Execute the statement
|
||||
return $stmt->execute();
|
||||
|
||||
} catch (PDOException $e) {
|
||||
die("Error updating device: " . $e->getMessage());
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user