WebCheez Posted April 27, 2012 Share Posted April 27, 2012 I have a table with several fields, one of which is an amount of days after which the row will be deleted. Every time the script is run, I want to check for old entries and delete them. How would I do this? Quote Link to comment https://forums.phpfreaks.com/topic/261731-delete-older-mysql-rows/ Share on other sites More sharing options...
xyph Posted April 27, 2012 Share Posted April 27, 2012 You should store the deletion date, not the number of days until it gets deleted. Did you at least store the date the row was created? DELETE FROM table WHERE NOW() > DATE_ADD(date_created, INTERVAL days_to_delete DAY) Quote Link to comment https://forums.phpfreaks.com/topic/261731-delete-older-mysql-rows/#findComment-1341262 Share on other sites More sharing options...
WebCheez Posted April 28, 2012 Author Share Posted April 28, 2012 When I run that, it says this when I print the error. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'delete DAY)' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/261731-delete-older-mysql-rows/#findComment-1341344 Share on other sites More sharing options...
xyph Posted April 28, 2012 Share Posted April 28, 2012 delete is a reserved word in MySQL http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html You can either use back-ticks around your columns that use reserved words (`), or better yet, change the name so it isn't a reserved word. Quote Link to comment https://forums.phpfreaks.com/topic/261731-delete-older-mysql-rows/#findComment-1341388 Share on other sites More sharing options...
WebCheez Posted April 28, 2012 Author Share Posted April 28, 2012 delete is a reserved word in MySQL http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html You can either use back-ticks around your columns that use reserved words (`), or better yet, change the name so it isn't a reserved word. Thank you! Works great. Quote Link to comment https://forums.phpfreaks.com/topic/261731-delete-older-mysql-rows/#findComment-1341436 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.