NOW() for DATETIME InnoDB Transaction guaranteed?

innodb, mysql, php, transactions

Solution

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.

Problem

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?

Original source

Related problems