Add updateWhere method to Domain model

Introduces updateWhere to allow updating multiple domain records based on specified WHERE conditions. This method builds dynamic SQL for flexible bulk updates.
This commit is contained in:
Hosteroid
2025-10-20 17:42:38 +03:00
parent 0b0532140e
commit c59a4e2c5b

View File

@@ -385,5 +385,38 @@ class Domain extends Model
return $stmt->fetchAll();
}
/**
* Update multiple domains based on WHERE conditions
*/
public function updateWhere(array $conditions, array $data): int
{
if (empty($conditions) || empty($data)) {
return 0;
}
// Build WHERE clause
$whereClause = [];
$params = [];
foreach ($conditions as $field => $value) {
$whereClause[] = "{$field} = ?";
$params[] = $value;
}
// Build SET clause
$setClause = [];
foreach ($data as $field => $value) {
$setClause[] = "{$field} = ?";
$params[] = $value;
}
$sql = "UPDATE domains SET " . implode(', ', $setClause) . " WHERE " . implode(' AND ', $whereClause);
$stmt = $this->db->prepare($sql);
$stmt->execute($params);
return $stmt->rowCount();
}
}