Jump to content

Get MySQL records in last hour


jjmusicpro

Recommended Posts

I have a program that checks the inputs of a form.

 

IN the database i input a time/date stamp of when these took place, plus the IP they came from.

I dont want someone to do more then 3 requets and hour.

 

Can I check the amout of records using a SQL query? or do i have to do it in code.

I know i can check a day range, but neve tried hours.

Link to comment
https://forums.phpfreaks.com/topic/137787-get-mysql-records-in-last-hour/
Share on other sites

you could add a row to the user table, that keeps track of times someone ran queries, and when they hit 3 in the last 60 minutes, it cuts them off until one hour since first query.  It would require a cron running every 1 or 5 minutes (a maintenance script to clean out out holds older than an hour).  I'm being vague, sry.  If you want help, feel free to ask.

 

url

http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html

 

mysql> SELECT '2008-12-31 23:59:59' + INTERVAL 1 SECOND;
        -> '2009-01-01 00:00:00'
mysql> SELECT INTERVAL 1 DAY + '2008-12-31';
        -> '2009-01-01'
mysql> SELECT '2005-01-01' - INTERVAL 1 SECOND;
        -> '2004-12-31 23:59:59'
mysql> SELECT DATE_ADD('2000-12-31 23:59:59',
    ->                 INTERVAL 1 SECOND);
        -> '2001-01-01 00:00:00'
mysql> SELECT DATE_ADD('2010-12-31 23:59:59',
    ->                 INTERVAL 1 DAY);
        -> '2011-01-01 23:59:59'
mysql> SELECT DATE_ADD('2100-12-31 23:59:59',
    ->                 INTERVAL '1:1' MINUTE_SECOND);
        -> '2101-01-01 00:01:00'
mysql> SELECT DATE_SUB('2005-01-01 00:00:00',
    ->                 INTERVAL '1 1:1:1' DAY_SECOND);
        -> '2004-12-30 22:58:59'
mysql> SELECT DATE_ADD('1900-01-01 00:00:00',
    ->                 INTERVAL '-1 10' DAY_HOUR);
        -> '1899-12-30 14:00:00'
mysql> SELECT DATE_SUB('1998-01-02', INTERVAL 31 DAY);
        -> '1997-12-02'
mysql> SELECT DATE_ADD('1992-12-31 23:59:59.000002',
    ->            INTERVAL '1.999999' SECOND_MICROSECOND);
        -> '1993-01-01 00:00:01.000001'

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.