Page 1 of 1
Auto Update DB Question
Posted: Sun Sep 11, 2011 3:41 pm
by rradu
HI
i'm new to this forum and a newbie in webdevelopment so, if my question is in wrong section mods, please move it!
my problem sounds like this:
a user send some data to server (trough php) actually a date & hour, at the respective hour i want some data in my DB to be updated (changed) even if user leaves the page (the date & hour may be 3 days ahead so he can't keep the browser open 3 days).
my question is: how can i do those changes. what program(preferably free)/language/technology should i use to make those changes.
as far as i know i can't do this with php.
THX!
Re: Auto Update DB Question
Posted: Sun Sep 11, 2011 4:20 pm
by ok
You are right, you can't do this by using PHP alone. However, you can use "cron". You add to cron a job, which will execute your script in a periodic manner (like, every 3 days). In your script you than check if there is something to be done.
Read more on cron:
http://en.wikipedia.org/wiki/Cron
Re: Auto Update DB Question
Posted: Tue Sep 13, 2011 12:57 pm
by rradu
that is really helpful but i'm not sure if it is suitable for my problem because in some cases my script might run every second and every delay (between runs) might be dezaster
i heard about trigers, and a saw that they can be used in postgres, could they solve my problem? or is there something where can i write somethign like :
if ($row.time==NOW()) then run(very_complicated_script);
and this to be run every second, or to detect "by itself" when to be run
Re: Auto Update DB Question
Posted: Tue Sep 13, 2011 7:38 pm
by califdon
What you are describing is rather difficult to do. If I understand your description, I don't think triggers would be of any use, since a trigger depends on one database action causing another database action, not based on time (although I could be wrong about that). However, it has been my observation, over nearly 20 years of teaching and developing databases, that nearly every time someone wants to make changes to a database at a certain time, they are approaching the problem incorrectly. What I recommend is that you store the date-time in the database, then base future actions on that date-time. What most newcomers fail to understand is that there is almost never a need "keep the database up to date." Unless a query is being processed against the database, it simply doesn't matter what is stored there! It only matters when you query the data! Thus, if the time criterion is stored for the record, your query and/or processing logic can always react properly. This is the same concept that dictates that you store a person's date-of-birth, NOT their age, because your queries can always calculate the age at the time the query is run. (Some people will argue that you might need to store the age at the time of a transaction, but I don't agree even with that, since the proper thing to do there is store both the date-of-birth and the transaction date.)
Re: Auto Update DB Question
Posted: Wed Sep 14, 2011 3:21 am
by VladSun