Page 1 of 1
Change value on database every 12mid night
Posted: Sat Dec 20, 2008 12:18 am
by Argie
How can I change the value of a row in a database everyday?
Eg: I have a column for balance, the default is 20, every time the user uses their balance it decreases. I want to change it every 12am to 20 again. How can I do that?
Thanks, H
Re: Change value on database every 12mid night
Posted: Sat Dec 20, 2008 1:18 am
by RobertGonzalez
Write a cron job that processes a script that will login to the database and reset that value every day at 12.
Re: Change value on database every 12mid night
Posted: Sat Dec 20, 2008 2:33 pm
by califdon
Argie wrote:How can I change the value of a row in a database everyday?
Eg: I have a column for balance, the default is 20, every time the user uses their balance it decreases. I want to change it every 12am to 20 again. How can I do that?
Thanks, H
Generally it's a bad idea to update a database based on a time interval. The better approach is to have a field in the table where the current date/time is stored each time that record is updated (or that field, if that's the logic). Then whenever you check a record for the balance, you compare the current date with the date last updated and if it's earlier than "today" you adjust the balance at that time. There's no need to constantly update all the records in the table.
Re: Change value on database every 12mid night
Posted: Sun Dec 21, 2008 9:46 pm
by Argie
thx to you all and to cron
