A
A
Alexey Sklyarov2018-02-09 14:43:15
PHP
Alexey Sklyarov, 2018-02-09 14:43:15

What is the correct way to commit the last value (at the end of the day) to the DB?

A script hangs on the crown that runs every 30 seconds. The script simply changes the values ​​in the database, I need to fix the latest value at the end of the day (write it in a column specially selected for this). What is the best way to do this?
The very first thing that comes to mind is to add a condition in the script:

если время >23.58 И время меньше <00.00,
 то запускаем функцию
But for some reason I don't like this approach. Is it possible to do it somehow differently (perhaps with trigger functions in mysql)?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nick Sdk, 2018-02-09
@lidacriss

it may be easier to always write to the second special table, but overwrite today's value

INSERT INTO table_name (`column1`, `column2`, `column3`, `date`)
VALUES ('value1', 'value2', 'value3', CURDATE())
ON DUPLICATE KEY UPDATE 
`column1`=VALUES(`column1`), 
`column2`=VALUES(`column2`), 
`column3`=VALUES(`column3`);

In such a table, the date column must be unique
. Such a query should write only 1 value for each day,
only it will be constantly overwritten and only the last value for each day will be relevant

A
alexdora, 2018-02-09
@alexdora

Create another script that will start every day at 0 o'clock and take the last value, write it down and turn off for a day
What you should not do - Complication with beautiful technologies

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question