PDO::ERRMODE_EXCEPTION] ); function mask_name($v) { if (!$v) return $v; $v = trim($v); $words = preg_split('/\s+/', $v); if (count($words) === 1) { $l = mb_strlen($v, 'UTF-8'); if ($l <= 2) return $v; return mb_substr($v, 0, 2, 'UTF-8') . str_repeat('*', $l - 2); } $first = $words[0]; $rest = array_slice($words, 1); $masked = array_map(function($w) { if (!$w) return ''; $init = mb_substr($w, 0, 1, 'UTF-8'); return $init . str_repeat('*', max(3, mb_strlen($w, 'UTF-8') - 1)); }, $rest); return $first . ' ' . implode(' ', $masked); } echo "=== Re-mask M_PatientName (format baru) ===\n"; $total = 0; $batch = 500; $last_id = 0; $stmt = $pdo->prepare( "UPDATE m_patient SET M_PatientName = ? WHERE M_PatientID = ?" ); while (true) { $rows = $pdo->query( "SELECT M_PatientID, M_PatientName_enc FROM m_patient WHERE M_PatientName_enc IS NOT NULL AND M_PatientID > {$last_id} ORDER BY M_PatientID ASC LIMIT {$batch}" )->fetchAll(PDO::FETCH_ASSOC); if (empty($rows)) break; foreach ($rows as $row) { $real_name = $enc->decrypt($row['M_PatientName_enc']); if ($real_name !== null) { $stmt->execute([mask_name($real_name), $row['M_PatientID']]); } $last_id = $row['M_PatientID']; $total++; } echo " {$total} rows...\n"; } echo "Selesai: {$total} rows\n";