S
S
Sergey questions2018-02-27 23:32:13
PHP
Sergey questions, 2018-02-27 23:32:13

Is it possible to temporarily write to the database without using cron?

Hello. Now the following question has arisen:
Is it possible somehow at the PHP or jquery level (I can’t even imagine how to implement it) to temporarily add or update a row in the database?

Those. for example, there is a products table , it has a row with an ID column of 3 , that row has an "action" column. In the engine (php, smarty) I change this value from 0 to 1 and vice versa. The question is this: is it possible to somehow set the action column to 1 for a certain period, for example, 2 hours, without using cron?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander, 2018-02-28
@smartycms

You can store a UNIX time stamp in the field. And at sampling from db to consider this value. Where :uts = time() - 7200, those same 2 hours. Then you can do without CRON and the MySQL scheduler, but you will have to pay for an additional int field in the table. Or you can add another table that will have 2 fields: product id and UNIX time stamp. Then you will need to add JOIN to the query.

SELECT p.* FROM products as p 
LEFT JOIN rel_table as rt
ON rt.id = p.id 
WHERE rt.uts IS NOT NULL AND rt.uts < :uts

This approach is somewhat more flexible.

S
SagePtr, 2018-02-27
@SagePtr

MySQL has a built-in scheduler, but it needs to be enabled in the config

O
Oleg, 2018-02-28
@402d

Promotional discounts for a few hours? Date time in this field. If it is more than the current discount is available

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question