beginTransaction(); $hash = password_hash('password', PASSWORD_DEFAULT); // Update all passwords $pdo->exec("UPDATE users SET password_hash = '{$hash}'"); // Update admin $pdo->exec("UPDATE users SET email = 'admin' WHERE role = 'admin'"); // Update petugas (handle multiple to avoid UNIQUE constraint violation) $stmt = $pdo->query("SELECT id FROM users WHERE role IN ('field_officer', 'staff', 'petugas') ORDER BY id ASC"); $petugas = $stmt->fetchAll(PDO::FETCH_ASSOC); foreach ($petugas as $index => $p) { // If there's only one, it will be 'petugas'. If more, 'petugas', 'petugas2', etc. $username = $index === 0 ? 'petugas' : 'petugas' . ($index + 1); $pdo->exec("UPDATE users SET email = '{$username}' WHERE id = " . $p['id']); } $pdo->commit(); echo "Database updated successfully.\n"; } catch (Exception $e) { $pdo->rollBack(); echo "Error updating database: " . $e->getMessage() . "\n"; }