Does using NOW() in 2+ queries in a single InnoDB transaction guarantee that the inserted datetime value will be exact in the database?
In other words, is the NOW(), even if you have more than 20 queries in a single transaction using it always going to be the same, or will it change?
Apparently it is not guaranteed across a transaction but can change from statement to statement. There is a workaround you can use as shown here:
BEGIN;
SELECT @now := NOW();
INSERT ... VALUES (..., @now, ...);
INSERT ... VALUES (..., @now, ...);
UPDATE ... @now ...;
COMMIT;
If you want to avoid that altogether just set the current date and time into a PHP variable and use that instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With