unit PM.Audit; { Mirrors api.php logAudit(). user_id may be NULL for pre-auth events; pass 0 to record without user. } interface uses System.SysUtils, FireDAC.Comp.Client, FireDAC.Stan.Param, PM.Database; procedure LogAudit(AUserId: Integer; const AAction, AIP: string); implementation procedure LogAudit(AUserId: Integer; const AAction, AIP: string); var LQ: TFDQuery; begin DB.Lock; try LQ := TFDQuery.Create(nil); try LQ.Connection := DB.Connection; LQ.SQL.Text := 'INSERT INTO audit_log (user_id, action, ip) VALUES (:uid, :action, :ip)'; if AUserId > 0 then LQ.ParamByName('uid').AsInteger := AUserId else LQ.ParamByName('uid').Clear; LQ.ParamByName('action').AsString := AAction; LQ.ParamByName('ip').AsString := AIP; LQ.ExecSQL; finally LQ.Free; end; finally DB.Unlock; end; end; end.