Get DATETIME in php and post it to MySQL for transaction consistency

datetime, innodb, mysql, php, transactions

Solution

One way could be:

<?php
$nowFormat = date('Y-m-d H:i:s');
$sql = "INSERT INTO table SET field='$nowFormat'";
$sql2 = "INSERT INTO table SET field='$nowFormat'";
...

Problem

Here is a link to the reason behind this question: NOW() for DATETIME InnoDB Transaction guaranteed? So to ensure a single transaction with any number of queries (20+ queries for example) has a 100% accurate and consistent NOW() value accross multiple tables, what is the php way to assign a variable equivalent of DATETIME using NOW() (not current TIMESTAMP).

Original source

Related problems