0
I need your help to identify sequential records in my database in a short period of time
Example:
$qdt_acao_suspeitas = 5; //5 ações consecutivas
$tempo = 10; //10 minuntos
If user X performs the action more than $qdt_acao_suspeitas
between time $tempo
displays an echo informing...
Sequential records in my bank:
Description:
mat3us made 5 equal shares in less than 10 minutes
guilherme21 made 5 equal shares in less than 10 minutes
I’ve tried something like
$flood = $pdo->querySELECT usuario,action,data,count(action) FROM eventos GROUP BY usuario,data having count(action) > 5");
in a while I make the following request
if($flood > 0){
...
}
would like a return of all users matching my request
but I’m sure my SELECT
not much to do with what I want to do and I’m already out of ideas
And how much is "short term"? 10 minutes? this will be difficult to do in the query, if it was for 1 minute or 1 hour, just group the date per minute or hour and make a Count, will have to do this in the code
– Ricardo Pontual
Which bank is it? Assuming Mysql, search by lead / lag de window functions , which allow you to see the previous records of an sql , https://www.geeksforgeeks.org/mysql-lead-and-lag-function/ , also timediff for the difference calculation https://www.w3schools.com/sql/func_mysql_timediff.asp , others SGBD has similar solutions
– Motta
@Ricardopunctual supposing it is 1 hour, as would be in practice?
– javinha
@Motta I’ve tried too, gives the error: Fatal error: Uncaught Error: Call to a Member Function fetch() on bool in ...
– javinha
gives a look at this other answer to get an idea: https://answall.com/a/460199/57220
– Ricardo Pontual
@javinha lead and lag works , but I believe it depends on the environment , version etc
– Motta
@Ricardopunctual I did in the same reasoning and always returns the Fatal Errol =@
– javinha
good without seeing the code it is difficult to help... edit and ask the question
– Ricardo Pontual
This would also be the case if thinking the case of a Function, very complicated rules can be solved by Function.
– Motta