1, first add a time field that was changed to m last time, such as change_at, and the data class recommends int or timespan. It would be better to use int, because you can use php's time () to compare time.
2. Define a function get_m () to get the value of m at a time. Perform an operation on m before taking the value:
Function get_m ()
{
$ now = time();
$ change _ at = get _ change _ at(); //Get the value of change_at, and the function writes it by itself.
$ m = read _ m(); //Get the real value in the database.
$ time _ span = $ now-$ change _ at;
//If the update conditions are not met, return directly;
if($time _ span & lt; 180)
Returns $ m;;
$ m+= floor($ time _ span/ 180);
$ change _ at+=(floor($ time _ span/ 180)* 180);
//Write the new m and change_at into the database.
save_m($m,$ change _ at);
Returns $ m;;
}
Read _ m (), get _ change _ at () and save _ m () write functions according to the specific database structure, or write database operation codes directly there without using functions.
This can ensure that the value obtained by the program is the same as that obtained when the database is automatically changed.