I
I
Ivan2020-05-26 13:43:12
PHP
Ivan, 2020-05-26 13:43:12

How to create a complex MySQL with an event correctly?

I'm trying to create a query to the database, save the data and set an event for the saved data in parallel.

Here is my request:

$this->db->query( "INSERT INTO " . PREFIX . "_users_balance
                      (name, payer, post_id, user_balance_hold) VALUES
                      ('$user', '$payer', '$post_id', '$money')"
            );
    $this->db->query( "CREATE EVENT $event_name
                      ON SCHEDULE EVERY $bs_time HOUR
                      STARTS CURRENT_TIMESTAMP
                      ENDS CURRENT_TIMESTAMP + INTERVAL $bs_time HOUR
                      DO
              INSERT INTO " . PREFIX . "_users_balance
                      (name, payer, post_id, user_balance_hold) VALUES
                      ('$user', '$payer', '$post_id', '$money')"
            );


Can these INSERT INTO and CREATE EVENT queries be combined into one?

Now the event is executed immediately upon request to the database, how not to execute it immediately, but only after the specified time has elapsed?

Thank you!
ps do not pay attention to the event itself.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stalker_RED, 2020-05-26
@Stalker_RED

Now the event is executed immediately when a request is made to the database
Duc because STARTS CURRENT_TIMESTAMP
It is not clear what exactly you want to do, it looks rather strange. Insert data immediately, and then after some time insert another copy?

F
FanatPHP, 2020-05-26
@FanatPHP

It is necessary to forget about events, about additional tables, and just store everything in one table.
Calculate money accrual by time

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question