Can anyone tell me what's wrong with me sql statement? I want it to delete all the table rows that the time interval is more than 1 minute. My sql statement does not show any errors but it wont delete any of the rows.
By the way I'm using the codeigniter framework.
$new_date = date('Y-m-d H:i:s', now());
$query = $this->db->query("DELETE FROM table WHERE 'date/time' < ('$new_date' - INTERVAL 1 minute)");
You're using single quotes around your column identifier instead of ticks
$query = $this->db->query("DELETE FROM table WHERE `date/time` < ('$new_date' - INTERVAL 1 minute)");
Also, $new_date = date('Y-m-d H:i:s', now());
should just be $new_date = date('Y-m-d H:i:s');
as PHP does not have a function called now()
. Or, even better, just use MySQL's built in date functions:
$query = $this->db->query("DELETE FROM table WHERE `date/time` < (NOW() - INTERVAL 1 minute)");
FYI, it is not common practice to use /
in column identifiers.