I personally find it easier use MySQL event scheduler than cron.
Enable it with
SET GLOBAL event_scheduler = ON;
and create an event like this:
CREATE EVENT name_of_event
ON SCHEDULE EVERY 1 DAY
STARTS '2014-01-18 00:00:00'
DO
DELETE FROM tbl_message WHERE DATEDIFF( NOW( ) , timestamp ) >=7;
and that’s it.
Read more about the syntax here and here is more general information about it.
Related Contents:
- Generic “Killed” error in PHP script
- How can I prevent SQL injection in PHP?
- mysql_fetch_array()/mysql_fetch_assoc()/mysql_fetch_row()/mysql_num_rows etc… expects parameter 1 to be resource
- Laravel Unknown Column ‘updated_at’
- PHP PDO: charset, set names?
- How can I execute PHP code from the command line?
- Lost connection to MySQL server at ‘reading initial communication packet’, system error: 0
- PHP & mySQL: Year 2038 Bug: What is it? How to solve it?
- how to check and set max_allowed_packet mysql variable [duplicate]
- Maximum execution time in phpMyadmin
- How to create cron job using PHP?
- How can I get enum possible values in a MySQL database?
- PDO mysql: How to know if insert was successful
- select count(*) from table of mysql in php
- Elegant way to search for UTF-8 files with BOM?
- Laravel: PDOException: could not find driver
- Do I have to guard against SQL injection if I used a dropdown?
- Project Links do not work on Wamp Server
- Is closing the mysql connection important?
- CRON command to run URL address every 5 minutes
- How to solve time out in phpmyadmin?
- Fatal error: Uncaught Error: Call to undefined function mysql_connect()
- getting the value of an extra pivot table column laravel
- How to create virtual column using MySQL SELECT?
- How to select rows where column value IS NOT NULL using CodeIgniter’s ActiveRecord?
- mysql server port number
- How to bind parameters to a raw DB query in Laravel that’s used on a model?
- Laravel 5 PDOException Could Not Find Driver [duplicate]
- adding 30 minutes to datetime php/mysql
- How to override the path of PHP to use the MAMP path?
- PHP myAdmin – Change Field Order (Move Up Or Down)
- PHP display image BLOB from MySQL [duplicate]
- convert date string to mysql datetime field
- MySQL INTO OUTFILE override existing file?
- The best way to get the first and last day of last month?
- Export MySQL database using PHP [closed]
- Checking for an empty result (PHP, PDO, and MySQL) [duplicate]
- Laravel classloader.php error failed to open stream: No such file or directory
- How to create a foreign key in phpmyadmin
- Show values from a MySQL database table inside a HTML table on a webpage
- How to store NULL values in datetime fields in MySQL?
- PHP MYSQL – Insert into without using column names but with autoincrement field
- How to set cron job URL for CodeIgniter?
- How to check with PHP if the script is being run from the console or browser request?
- PHP: running scheduled jobs (cron jobs)
- Incorrect Integer (2147483647) is inserted into MySQL?
- Laravel Eloquent LEFT JOIN WHERE NULL
- Insert multiple rows with one query MySQL
- How can I see how many MySQL connections are open?
- Insert array into MySQL database with PHP