NOW () guaranteed for transaction DATETIME InnoDB?

Does NOW () in 2+ queries in a single InnoDB transaction guarantee that the entered datetime value will be accurate in the database?

In other words, is it NOW (), even if you have more than 20 requests in one transaction, will it always be the same or will it change?

+5
source share
1 answer

Apparently, it is not guaranteed in the transaction, but may change from operator to operator. There is a workaround that you can use as shown here :

BEGIN; SELECT @now := NOW(); INSERT ... VALUES (..., @now, ...); INSERT ... VALUES (..., @now, ...); UPDATE ... @now ...; COMMIT; 

If you want to avoid this, just set the current date and time to a PHP variable and use it instead.

+5
source

Source: https://habr.com/ru/post/913071/


All Articles