chop Posted June 6, 2012 Share Posted June 6, 2012 In my "Dues_Date" column I have "2012-10-01" which is the time the dues must be paid for the coming term. I want that date to update itself, if possible, to "2013-10-01" on precisely the original dues date above. Can mySql do this by itself or do I need to write a script for it? In that case, how does the script get run if I'm, let's say, in Jamaica drinking a pina colada at the time? Link to comment Share on other sites More sharing options...
Larry Posted June 6, 2012 Share Posted June 6, 2012 MySQL cannot do that itself, you have to trigger that change. You could create a cronjob that invokes a script that does it automatically. Link to comment Share on other sites More sharing options...
margaux Posted June 6, 2012 Share Posted June 6, 2012 You will need to create a script to update that column and use cron to schedule it to run automatically. There's a chapter in Larry's Advanced PHP book on scheduling jobs. Link to comment Share on other sites More sharing options...
chop Posted June 6, 2012 Author Share Posted June 6, 2012 cron - I've heard the term but am not familiar with it. Will check into it -thanks Link to comment Share on other sites More sharing options...
HartleySan Posted June 6, 2012 Share Posted June 6, 2012 I've never heard of a cronjob myself, but you can also write a MySQL trigger, which will execute one or more statements automatically when certain conditions are met. Here's a good intro to the topic: http://net.tutsplus.com/tutorials/databases/introduction-to-mysql-triggers/ Link to comment Share on other sites More sharing options...
Larry Posted June 7, 2012 Share Posted June 7, 2012 The problem with triggers is that they are internal to the database. A trigger can have a secondary action occur when a primary action occurs, but the primary action would still need to be caused by something outside of the database. Link to comment Share on other sites More sharing options...
HartleySan Posted June 7, 2012 Share Posted June 7, 2012 Can't you easily create a trigger that fires at a particular time though? Link to comment Share on other sites More sharing options...
Larry Posted June 8, 2012 Share Posted June 8, 2012 Triggers cannot be fired at a particular time. Triggers react to other events. Instead of a cronjob, however, one could use MySQL's event scheduler, assuming that's supported in your version of MySQL. Link to comment Share on other sites More sharing options...
HartleySan Posted June 9, 2012 Share Posted June 9, 2012 Good to know. Thanks a lot, Larry. Link to comment Share on other sites More sharing options...
Recommended Posts