I’m completely new to MySQL. I’m attempting to write a query that inserts a row into the table, but only if the previous row was inserted over 5 minutes ago. Additionally, I’d like my PHP code to have some way of knowing whether the data was inserted or not. This is my attempt:
IF (SELECT max(EntryDate) from MyTable) < DATE_SUB(CURRENT_DATE() INTERVAL 5 MINUTE) THEN
INSERT INTO MyTable (...) values (...)
ELSE
Select false
END IF
Unfortunately, but not unsurprisingly, that gives a syntax error (the error is being very vague about the location of the problem).
Am I doing something stupid?
Use WHERE NOT EXISTS and check for a row with
>time-5 minutes.