Page 1 of 1
Changing a database value at a certain time.
Posted: Thu Dec 04, 2008 1:16 am
by kryppienation
I am trying to set a certain field "daily" to reset to the value of 200 in an entire table throughout all records. I am not sure how to work with time. I would like to also watch the time remaining until the reset happens... Now this time does not have to live, just a post of the time remaining that updates when i refresh is quite fine. I am not sure if i need to make another database table to hold the information or not, i am sure that i most likely do... which is completely fine. I am wondering if someone knows how i can do this?
I only need to do this one time in a 24 hours period. Like once a midnight... i don't know if that makes it easier or not... but perhaps a bit less confusing. Basically i need to know how to run an update statement every 24 hours.
EDIT: I use windows OS too. Apache and MySQL if that matters at all.
Thanks Everyone!
KN
Re: Changing a database value at a certain time.
Posted: Thu Dec 04, 2008 3:47 am
by Mark Baker
You write a simple php script that you can run from the command line to do the task, then use Windows scheduled tasks to run that script at the time and frequency of your choosing
Re: Changing a database value at a certain time.
Posted: Thu Dec 04, 2008 4:05 am
by xQuasar
Is there a way to do it just with PHP scripts, no other programs involved? I'm also interested in this, I'm looking for a way to make a column increase in value every half hour (for every row).
Re: Changing a database value at a certain time.
Posted: Thu Dec 04, 2008 4:07 am
by kryppienation
Ok I have done that, it still didn't change the values in my database. here is what i got.
this is all of the stuff in "RUN:"
C:\xampp\php\php.exe C:\xampp\htdocs\kryppienation\admin\changemotivation.php
it opens the php.exe CLI but it's not reading the file... i also tried:
C:\xampp\php\php.exe changemotivation.php
when i did this i made sure that the changemotivation.php and the included db.php were in the c:\xampp\php folder.
didn't work either
Thanks.
here is the code in the php file.
Code: Select all
<?php
include_once('../includes/db.php');
$setmotivation = 'update knusers set motivation = "200"';
DB::connect($DB_database);
DB::query($setmotivation, "Name of query for error handling");
DB::close();
?>
Re: Changing a database value at a certain time.
Posted: Thu Dec 04, 2008 4:16 am
by Mark Baker
xQuasar wrote:Is there a way to do it just with PHP scripts, no other programs involved? I'm also interested in this, I'm looking for a way to make a column increase in value every half hour (for every row).
Not unless you have that PHP script
permanently running in the background... and you can't do that from a web page.
Cron, or its equivalent on whatever your operating system is, is the best way to do it.
Re: Changing a database value at a certain time.
Posted: Thu Dec 04, 2008 4:19 am
by Mark Baker
kryppienation wrote:Ok I have done that, it still didn't change the values in my database. here is what i got.
Make sure your start directory is correct, or have the script chdir to the correct directory as the first thing it does.
Run phpinfo from the command line to make sure you're picking up the correct php.ini file (to ensure that your php.ini path is correctly set). [I believe xampp has different php.ini files for web and command line use]
Re: Changing a database value at a certain time.
Posted: Thu Dec 04, 2008 4:31 am
by kryppienation
what should the start directory be pointing to? I am not familiar with how to use the CLI properly. What would i need to type into there to check the php.ini file it is reading? Please forgive me, this is the first time i have ever used this and i am trying to get this to work very badly.
Thank you
EDIT: after checking in the folders i found this...
there is a php.ini file in the C:\xampp\apache\bin (in my webserver check of the phpinfo() i get this location)
there is a php.ini file in the C:\xampp\php (this is where the CLI is located, i don't know how to check, but my guess the CLI reads this one)
so... i know that much. can you help me to solve what i need to do to make it work correctly?
Re: Changing a database value at a certain time.
Posted: Thu Dec 04, 2008 4:57 am
by Mark Baker
From the command line:
The -r allows you to execute PHP code passed in directly on the command line. In this case, executing the phpinfo() function.
If your Windows command line buffer can't handle all this output, use
Code: Select all
\xampp\php\php -r phpinfo(); > phpinfo.txt
to write the output to a text file.
You can then read that output to get all the information about your php configuration, including which php.ini file it's using, and the path settings.
Re: Changing a database value at a certain time.
Posted: Thu Dec 04, 2008 5:01 am
by Mark Baker
kryppienation wrote:what should the start directory be pointing to?
Given that your code has the following line:
Code: Select all
include_once('../includes/db.php');
Then it needs to be executing in a directory where this relative path would be valid. I'd expect this to be in the "C:\xampp\htdocs\kryppienation\admin" directory
{SOLVED}Re: Changing a database value at a certain time.
Posted: Thu Dec 04, 2008 5:11 am
by kryppienation
Man you rock thanks for all your help. Case closed, works!!!
Much Appreciation,
~KN
Re: Changing a database value at a certain time.
Posted: Thu Dec 04, 2008 5:38 am
by Mark Baker
It's very useful to know how to use the command line.... and I highly recommend that every PHP developer should read the appropriate
manual pages
I reckon that nearly half the problems that people here ask for help with could be identified (by validating the syntax of a file using "php -l <filename>" from the command line).