prepare("INSERT INTO audit_logs (tenant_id, user_id, action, entity_type, entity_id, old_data, new_data, ip_address, user_agent, metadata) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); // This would be populated from the global Request context $tenantId = $GLOBALS['current_tenant_id'] ?? null; $userId = $GLOBALS['current_user_id'] ?? null; $stmt->execute([ $tenantId, $userId, $action, $entityType, $entityId, $oldData ? json_encode($oldData) : null, $newData ? json_encode($newData) : null, $_SERVER['REMOTE_ADDR'] ?? null, $_SERVER['HTTP_USER_AGENT'] ?? null, $metadata ? json_encode($metadata) : null ]); } }